Suppose in a custom python module written in C, I declare the variable:
static int module_state;
The functions in my module set the state of this variable. If I want to know the value of module_state
, I can declare a getter function like this:
PyObject * get_module_state(PyObject *self)
{
return PyLong_FromLong(module_state);
}
On python (3) I could simply do:
import module
...
state = module.get_module_state()
However, I want to expose it as a variable:
import module
state = module.module_state
I looked at PyMemberDef
and PyGetterSetterDef
in the API but I am confused about how to use them to expose the variable. Generally speaking I don't want the python user to be able to modify the variable.
The purpose of this variable is very similar to errno
, and I want to make it available as transparently as possible.