Default parameters from Python in a specific C ++ function?
I have nested Python in my C ++ application and I have created several C functions that can be called from Python.
To get the arguments, I am currently doing:
if (!PyArg_ParseTuple(args, "zk", ¶m1, ¶m2))
return NULL;
However, I want it to param2
be optional. How can I check them separately?
+3
user2058002
source
to share
1 answer
|
Indicates that the rest of the arguments in the Python argument list are optional. C variables corresponding to optional arguments must be initialized by default - when no optional argument is specified, it
PyArg_ParseTuple()
does not affect the contents of the corresponding variable (s).
param2 = 42;
if (!PyArg_ParseTuple(args, "z|k", ¶m1, ¶m2))
return NULL;
+3
source to share