python wrapper question

G

Garett Shulman

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
 
C

Christopher T King

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top