C Extension question-> How handle lists and tuples as arguments?
Gerhard Häring
gh at ghaering.de
Wed Oct 8 16:57:59 EDT 2003
Christian Seberino wrote:
> Py_ParseTuple is a great C function to set C variables from
> Python objects in a C extension.
>
> Usage is straight forward for integers and strings but I'm wondering
> what to do if I ever want to send in a list or tuple.
>
> First problem is that we don't know the LENGTH of the list/tuple.
>
> Second problem is we don't know the TYPES of the elements.
I don't understand your problem. For "other" parameters, use "O" as
format character in ParseTuple...(). Then if you need to check if the
passed parameter is a sequence (either tuple or list), you can just use
PySequenceCheck().
For the rest, use the functions for the sequence protocol, like
PySequence_Length() and the like.
HTH,
-- Gerhard
More information about the Python-list
mailing list