0

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!")

cheers
chardson

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by scru
0

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.
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.