How send LIST to C extension?

vincent wehren vincent at visualtrans.de
Sun Nov 23 04:29:19 EST 2003


"Christian Seberino" <seberino at spawar.navy.mil> schrieb im Newsbeitrag
news:bf23f78f.0311221144.74df07eb at posting.google.com...
| Vincent
|
| Thanks.  Your example with "0" will make *seq point to the list I believe.

Make sure it's "O" (the letter O) not "0"...



|
| Can I extract the elements of the list into C variables
|
| with PyArg_ParseTuple if I didn't want to work with PyObject directly??

Sure. That's the whole point... You can use seq (which is a PyObject) and
subject it to all kinds
of functions ( e.g. PyList_GET_ITEM(seq, i) which retuns the i'th item of
list seq ))


|
| Perhaps this is a bad idea and your way is always better???
| (python.org docs had example of extracting elements of a tuple
| with PyArg_ParseTuple but I couldn't do it.)

So, what did you try?

Vincent Wehren


|
| Chris
|
|
|
| "vincent wehren" <vincent at visualtrans.de> wrote in message
news:<bpnmr7$flr$1 at news3.tilbu1.nb.home.nl>...
| > "Christian Seberino" <seberino at spawar.navy.mil> schrieb im Newsbeitrag
| > news:bf23f78f.0311211356.7368197c at posting.google.com...
| > | I already sent a post about problems sending list as argument in a C
| >  extension.
| > |
| > | I think I'll start over and just ask if anyone has done this
successfully.
| > |
| > | Can you send me code that does this??
| > |
| > | (I tried PyArg_ParseTuple("[ii]",...) but apparently there is more to
it
| >  than
| > | just adding brackets.
| >
| >
| > In your function you need something like
| >
| >     PyObject* seq;
| >
| >     if(!PyArg_ParsTuple(args, "O", &seq))
| >        return 0;
| >
| >
| > To do something useful with seq, you might want to look at the
PySequence_*
| > function family in the Python/C API Reference Manual (s.
| > http://www.python.org/doc/current/api/sequence.html)
| >
| > HTH,
| > Vincent Wehren
| >
| >
| >
| >
| >
| > |
| > | chris






More information about the Python-list mailing list