I'm writing a program that involves callbacks called from another module, and which need to access a global variable.
It seems that changes assigned to the global variable are not seen in the callback function, which only sees the original assignment. I'm guessing due to the import from the other module.
What is the proper way to write this pattern?
First module:
# a.py
from b import runb
myGlobal=None
def init():
global myGlobal
myGlobal=1
def callback():
print myGlobal
def main():
init()
runb()
if __name__=='__main__':
main()
Second module:
#b.py
def runb():
from a import callback
callback()
I would expect this program to print '1', but instead it prints 'None'
EDIT: init can only be called once (it is a simplification of a complex program)