J
Joachim Dahl
I am updating an extension module from Python2.6 to Python3.
I used to pass character codes to the extension module, for example, I
would write:
with the corresponding C extension routine defined as follows:
static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds)
{
char foo;
char *kwlist[] = {"foo", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwrds, "c", kwlist, &foo))
return NULL;
...
In Python3.0 this also works, but in Python3.1 I get the following
error:
TypeError: argument 1 must be a byte string of length 1, not str
and I seem to be supposed to writeinstead. From the Python C API, I have not been able to explain this
new behavior.
What is the correct way to pass a single character argument to
Python3.1
extension modules?
I used to pass character codes to the extension module, for example, I
would write:
with the corresponding C extension routine defined as follows:
static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds)
{
char foo;
char *kwlist[] = {"foo", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwrds, "c", kwlist, &foo))
return NULL;
...
In Python3.0 this also works, but in Python3.1 I get the following
error:
TypeError: argument 1 must be a byte string of length 1, not str
and I seem to be supposed to writeinstead. From the Python C API, I have not been able to explain this
new behavior.
What is the correct way to pass a single character argument to
Python3.1
extension modules?