hi there,

i'm using the PyArg_ParseTuple() function in my python bindings for some C code. the code i'm wrapping has two functions, one that returns a default value instead of an error if an error would have occurred, and one that returns an error. i simply want to use one function, and an optional argument.

Using PyArg_ParseTuple(), how might I tell if the optional argument was filled? the only thing i could come up with was parsing twice with two different initial values (in case you initialized to the default value, and said "don't use the default, it didn't change!")


You have to initialize the variable to something else and check if it changed.

int x;
int y = 4;

if (!PyArg_ParseTuple(args, "i|i", &x, &y))
    return NULL;

if (y != 4)
    // non-default argument supplied.