PyArg_ParseTuple part 2
Michael Hudson
mwh at python.net
Wed Jun 13 14:38:37 EDT 2001
"John" <john.thai at dspfactory.com> writes:
> Hi,
>
> In an extended python c function, I use PyArg_ParseTuple to extract a
> list object from python. I then use PyList_AsTuple to get a tuple version
> of the list. I'm expecting an list of 2 integers, so I use PyArg_ParseTuple
> again, passing in this new derived tuple, and specifying "ii". Should this
> not work? First, after I call PyList_AsTuple, I get NULL back instead of a
> PyObject. Second, lets say I pass variable x (from python) = [1,2] into my
> function, right after making this function call foo(x), no matter what I
> type, either x, or just enter, I get the following msg:
>
> SystemError: C:\Code\python\dist\src\Objects\listobject.c:1317: bad argument
> to
> internal function
>
> Anyone know what's going on?
Err, you are specifying your function as METH_VARARGS, right? (Just a
guess). Otherwise, how about showing us some code - I can't really
follow your description above.
> Related questions: Is there a fast way of extracting elements from a list,
> other than using PyList_GetItem, then converting the PyObject into the type
> you are looking for?
Well, there's PyList_GET_ITEM, but no, not really. Lists store
PyObject*s - what were you expecting?
> And why isn't there a PyInt_FromInt(int) function?
There's PyInt_FromLong - is that what you're after?
Cheers,
M.
--
Presumably pronging in the wrong place zogs it.
-- Aldabra Stoddart, ucam.chat
More information about the Python-list
mailing list