PyArg_ParseTuple and dict

Jeff Epler jepler at unpythonic.net
Sun Jun 5 22:36:04 EDT 2005


I tried to recreate the problem based on what you described in your
message.  I was unable to recreate the problem.

I wrote the following file "sjh.c":

#include <Python.h>

PyObject *f(PyObject *self, PyObject *args) {
    PyObject *ob = NULL;
    if(!PyArg_ParseTuple(args, "O", &ob)) return NULL;
    Py_INCREF(Py_None); 
    return Py_None;
}

PyMethodDef methods[] = {
    {"f", (PyCFunction)f, METH_VARARGS, "test function"},
    {NULL}
};

void initsjh() {
    Py_InitModule3("sjh", methods, "test module");
}

I compiled it for Python 2.3:
$ gcc sjh.c -I/usr/include/python2.3 -L/usr/lib/python2.3/config -lpython2.3 -shared -o sjh.so

and I tested it:
$ python -c 'import sjh; print sjh.f(1)'
None
$ python -c 'import sjh; print sjh.f({})'
None
$ python -c 'import sjh; print sjh.f({None: None})'
None

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20050605/ed944b0d/attachment.sig>


More information about the Python-list mailing list