optional arguments in c extensions

P

Paul Probert

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
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top