C FFI: easy conversion from list to argv?

Discussion in 'Python' started by Burton Samograd, Apr 17, 2006.

  1. 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
     
    Burton Samograd, Apr 17, 2006
    #1
    1. Advertising

  2. Burton Samograd <> 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 = 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
     
    Burton Samograd, Apr 17, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bret

    char **argv vs. char* argv[]

    Bret, Aug 31, 2003, in forum: C Programming
    Replies:
    21
    Views:
    4,662
    Richard Heathfield
    Sep 3, 2003
  2. David
    Replies:
    10
    Views:
    6,049
    Richard Heathfield
    Sep 15, 2003
  3. Hal Styli
    Replies:
    14
    Views:
    1,697
    Old Wolf
    Jan 20, 2004
  4. =?ISO-8859-1?Q?Thomas_N=FCcker?=

    sys.argv[0] - 'module' object has no attribute 'argv'

    =?ISO-8859-1?Q?Thomas_N=FCcker?=, Jun 30, 2003, in forum: Python
    Replies:
    0
    Views:
    974
    =?ISO-8859-1?Q?Thomas_N=FCcker?=
    Jun 30, 2003
  5. John Croisant
    Replies:
    0
    Views:
    110
    John Croisant
    Oct 25, 2009
Loading...

Share This Page