python wrapper question
Christopher T King
squirrel at WPI.EDU
Tue Jul 27 10:33:24 EDT 2004
On Mon, 26 Jul 2004, Garett Shulman wrote:
> Hello, I am trying to create a wrapper for a function with the following
> prototype:
> int ap_get_playlist(int session, int *argc, char ***the_list);
> I'm not quite sure how to construct the Py_BuildValue. I would like the
> python function to return a list of strings. However, the length of the
> list, (*argc in the function call), will vary at run time. Is it
> possible to have a wrapper function return a list whose size is not know
> at compile time? Thanks for any suggestions. -Garett
You will have to construct the list manually, using PyList_New(argc) to
make a new list of the correct size, PyString_FromString(...) for each
item to make a string out of it, and PyList_SET_ITEM(...) to store each
item into the list. You can then pass the resulting list to Py_BuildValue
as an "O" type.
Alternatively, you can wrap the above list-building goo in a function
that accepts a char ** and returns a PyObject *, and then use the magic
"O&" type in Py_BuildValue, passing it first your list-building function
and then the string array.
Hope this all made some sense :P
More information about the Python-list
mailing list