PyListObject & C Modules

Joshua Gramlich jggramlich at yahoo.com
Thu Sep 5 17:40:19 EDT 2002


Okay...I finally got it.

in:

if(!PyArg_ParseTuple(args, "O!", &list))
    return NULL;


The option "O!" doesn't work.  If you look at the
<sarcasm>tutorial</sarcasm>*  :D


http://www.python.org/doc/current/ext/parseTuple.html

...you'll see this:

"O" (object) [PyObject *] 
Store a Python object (without any conversion) in a C object pointer.
The C program thus receives the actual object that was passed. The
object's reference count is not increased. The pointer stored is not
NULL.

"O!" (object) [typeobject, PyObject *] 
Store a Python object in a C object pointer. This is similar to "O",
but takes two C arguments: the first is the address of a Python type
object, the second is the address of the C variable (of type PyObject
*) into which the object pointer is stored. If the Python object does
not have the required type, TypeError is raised.

Removing the '!' from the PyArg_ParseTuple solved the problem (before
it was returning TypeError), and when I ask for item 3 (really 4) I
get the following:


[d0ora3 ~/work/grid_query/test]$ python hello.py 
[0, 3, 8, 22, 9]
[22]
[d0ora3 ~/work/grid_query/test]$ 



THANKS FOR ALL THE HELP!!!



More information about the Python-list mailing list