You have a python module written with SWIG (http://swig.org/), named "swigMod1", and a global C variable in the .i extension file called "int A1=0;". Typing "import swigMod1" and "swigMod1.cvar.A1" under the python environment, imports the new extension and allows you to read and modify A1 during the execution time.
If you are running two swig modules, a syntax like "swigMod1.cvar.A1=swigMod2.cvar.A2" copies the variable A1 (in the first module) into A2 (in the second module).
This is a very useful functionality in my project, and I'd like to preserve it in the next considered case.
You have now another extension named "cMod", this time written via the classical C API (https://docs.python.org/2.7/extending/extending.html#). There is again a C global variable in the source code ("int B=1;"), and you want to access it like in the example before, but typing "cMod.cvar.B" doesn't work because it is only a SWIG feature.
Is it possible to obtain anyway results like "cMod.cvar.B" and "swigModule.cvar.A1=cMod.cvar.B" ?
Please note how I declared integers only for simplicity but in practice I face other types and I'd like to find a general solution. I also omitted the proper checking for avoiding undesired effects.
cvarPython object and move your global variables to C-level struct fields in that object, then provide Python-level access through thetp_membersinterface.globalsstruct is where globals would go, and unless I screwed something up, it should be a valid Python object that exposes its struct fields as Python attributes, so inserting it into your module dict should provide Python-level access to those fields.