An simple Python extension in C
- by celil
I am trying to create a simple python extension module. I compiled the following code into a transit.so dynamic module
#include <python2.6/Python.h>
static PyObject*
_print(PyObject* self, PyObject* args)
{
return Py_BuildValue("i", 10);
}
static PyMethodDef TransitMethods[] = {
{"print", _print, METH_VARARGS, ""},
{NULL, NULL, 0, NULL}
};
PyMODINIT_FUNC
inittransit(void)
{
Py_InitModule("transit", TransitMethods);
}
However, trying to call this from python
import transit
transit.print()
I obtain an error message
File "test.py", line 2
transit.print()
^
SyntaxError: invalid syntax
What's wrong with my code?