C FFI: easy conversion from list to argv?

Burton Samograd kruhftREMOVE at gmail.com
Mon Apr 17 14:59:52 EDT 2006


Burton Samograd <kruhftREMOVE at gmail.com> writes:
> I'm trying to update the fuse python bindings to my app and I was
> curious if there were any C utility functions that would turn a
> sys.argv into a C style argv array, or am I going to have to write
> those myself?

Following up to myself again...found the solution:

----------------------------------------------------------------------
PyObject *argv; /* value from PyArg_ParseTupleAndKeywords elsewhere */
int _argc = PySequence_Length(argv);
char **_argv = malloc(_argc*sizeof(char**));
int i;
for(i=0;i<_argc;i++)
    _argv[i] = PyString_AsString(PyList_GetItem(argv, i));
----------------------------------------------------------------------

Could probabaly use some error checking but it works...

-- 
burton samograd					kruhft .at. gmail
kruhft.blogspot.com	www.myspace.com/kruhft	metashell.blogspot.com



More information about the Python-list mailing list