Help in unwrapping a PyObject* returned by an embedded Python function
Read Roberts
rroberts at adobe.com
Mon Jan 12 12:17:48 EST 2004
Thank you taking the time to read and reply.
In fact, I did try all combinations of
in the Python call-back function :
return myString
return (myString)
and, in the C calling function,
PyArg_ParseTuple(pyStringResult, "s", myString)
PyArg_ParseTuple(pyStringResult, "(s)", myString)
Also, the Python documentation (and other working code examples I
have) indicate that 'PyArg_ParseTuple', unlike BuildValues, always
assumes the arguments are supplied in a argument tuple, even if there
is only one argumen.
I speculate that an argument list object, as required by
PyArg_ParseTuple, is not in fact a simple tuple., and that
PyArg_ParseTuple cannot be used to parse a regular tuple. Any idea if
this is correct?
>In comp.lang.python, you wrote:
>
>> Why does PyArg_ParseTuple fail to parse a return value which is a tuple?
>>
>> However, the following does not work:
>> from Python callback function: return (myString)
>> in calling C function:
>> if (!PyArg_ParseTuple(pyStringResult, "s", name)) {
>> dbprintf(4, "c: failed to parse return value\n");
>> PyErr_Clear();
>> }
>> PyArg_ParseTuple fails, and returns NULL. How come? By the
>> documentation, I would think that PyArg_ParseTuple would parse any
>> Python tuple object.
>
>To me "s" looks like you are expecting a string and not a tuple. You can
>verify that by seeing what happens if you do 'return "blabla"' instead
>of 'return ("blabla",)'.
>If that works, I would think that changing the "s" to a tuple (ie
>something like "(s)" ) should do the trick.
>
>
>
>Albert
>--
>Unlike popular belief, the .doc format is not an open publically
>available format.
--
-----------------------------------------------------------------------------------------
Read K. Roberts rroberts at adobe.com
Adobe Systems San Jose TW12 (408)-536-4402 on Weds
San Francisco (415) 642-5642 Mon, Tues, Thurs, Fri
More information about the Python-list
mailing list