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", &param1, &param2))
  return NULL;

      

However, I want it to param2

be optional. How can I check them separately?

+3


source to share


1 answer


You do not know.

|

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", &param1, &param2))
  return NULL;

      

+3


source







All Articles