I'm just starting to play with Python C extensions and am curious as to why a C function, which is callable from Python must take 2 PyObject* arguments and return a PyObject*. I wrote the following "Hello World" extension:
#include <Python.h>
static PyObject *
hello_world(PyObject *self, PyObject *noargs)
{
printf("Hello World\n");
return Py_BuildValue("");
}
// Module functions table.
static PyMethodDef
module_functions[] = {
{ "hello_world", hello_world, METH_NOARGS, "hello world method" },
{ NULL }
};
// This function is called to initialize the module.
PyMODINIT_FUNC
inittesty2(void)
{
Py_InitModule("testy2", module_functions);
}
Why can't I (especially with METH_NOARGS) use the following hello_world method:
static void
hello_world()
{
printf("Hello World\n");
}
?
Py_None
, notPyNone
. Also there'sPy_RETURN_NONE
similar toPy_RETURN_TRUE
andPy_RETURN_FALSE
. – Reeba