I am writing a simple C wrapper for a Python module. What I need to do is create a new PyObject* that represents None. I can’t figure out how to do this. Is there a simple function that will return a PyObject* pointing to None, similar to how PyTuple_New returns a PyObject* pointing to a new tuple or PyString_FromString` returns one pointing to a python string?
Note Is it possible that, when calling a function as below, passing a C NULL will work? example:
//pFunc points to a function with 2 arguments
PyObject *pArgs = PyTuple_New(2);
PyTuple_SetItem(pArgs, 0, PyString_FromString("hello"));
PyTuple_SetItem(pArgs, 1, NULL); // <--- will this create a python object representing None?
pValue = PyObject_CallObject(pFunc, pArgs);
According to the documentation,
Noneis a singleton, and is accessible from C code asPy_None.