optional arguments in c extensions

Discussion in 'Python' started by Paul Probert, Oct 24, 2003.

  1. Paul Probert

    Paul Probert Guest

    I am trying to write a c interface function to be called with some
    optional arguments. In the python documentation section 5.5
    "Parsing arguments and building values" it seems you can do it like this:

    PyObject *do_stuff( PyObject *self, PyObject *args){
    PyObject *thing = NULL;
    char *fname;
    if( !PyArg_ParseTuple(args, "s|O", &fname, &thing)){
    PyErr_SetString(PyExc_RuntimeError, "error parsing input");
    return NULL;
    }
    ...

    The "|" in "s|O" is supposed to let you call the function with only
    one argument. But, I get an exception:

    TypeError: do_stuff() takes exactly 2 arguments (1 given)

    What am I missing?

    Paul Probert
    University of Wisconsin
    Paul Probert, Oct 24, 2003
    #1
    1. Advertising

  2. Paul Probert

    Paul Probert Guest

    Oops, the problem was elsewhere. Never mind !

    --
    Paul Probert
    The University of Wisconsin-Madison
    Paul Probert, Oct 24, 2003
    #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. Roger Upole
    Replies:
    0
    Views:
    391
    Roger Upole
    Dec 1, 2003
  2. Ezequiel, Justin

    optional arguments to pattern.findall()

    Ezequiel, Justin, May 5, 2004, in forum: Python
    Replies:
    1
    Views:
    330
    Peter Otten
    May 5, 2004
  3. Jason

    optional arguments..

    Jason, Apr 28, 2006, in forum: C Programming
    Replies:
    5
    Views:
    303
    Peter Shaggy Haywood
    Apr 30, 2006
  4. Rob Hoelz

    Getting at optional arguments

    Rob Hoelz, Jan 15, 2007, in forum: C Programming
    Replies:
    6
    Views:
    344
    Default User
    Jan 16, 2007
  5. braver
    Replies:
    3
    Views:
    452
    Steven Bethard
    Nov 12, 2007
Loading...

Share This Page