define global in a python module from C api
- by wiso
Sorry for the trivial question, but I can't find this infomation from the manual. I am developping a module for python using C api; how can I create a variabile that is seen as global from python? For example if my module is module I want to create a variable g that do this job:
import module
print module.g
in particular g is an integer.
Solution from Alex Martelli
PyObject *m = Py_InitModule("mymodule", mymoduleMethods);
PyObject *v = PyLong_FromLong((long) 23);
PyObject_SetAttrString(m, "L", v);
Py_DECREF(v);