469,923 Members | 1,777 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

C FFI: easy conversion from list to argv?

Hi,

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?

Thanks.

--
burton samograd kruhft .at. gmail
kruhft.blogspot.com www.myspace.com/kruhft metashell.blogspot.com
Apr 17 '06 #1
1 1124
Burton Samograd <kr**********@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
Apr 17 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by CAFxX | last post: by
22 posts views Thread by kalio80 | last post: by
3 posts views Thread by Siemel Naran | last post: by
1 post views Thread by Bucco | last post: by
4 posts views Thread by Johnny Drama | last post: by
7 posts views Thread by billbaitsg | last post: by
15 posts views Thread by bcpkh | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.