Accessing module global variable in a cython module from python

Let’s say you have a global module variable in your cython script:

cdef public bint myVal = True

Such a variable is hidden in C space, so you cannot access it directly from python space.
If you want to be able to change this value from another python script, you can just make a wrapper function around it, e.g.:

cpdef set_myval(bint val):
global myVal
myVal = val

Now you can access the variable in the cython module.

Wednesday, November 18th, 2015 Cython, Python No Comments