define global in a python module from C api
Posted
by wiso
on Stack Overflow
See other posts from Stack Overflow
or by wiso
Published on 2010-06-08T20:56:46Z
Indexed on
2010/06/08
21:42 UTC
Read the original article
Hit count: 204
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);
© Stack Overflow or respective owner