Global variables in modules...

ttsiodras at gmail.com ttsiodras at gmail.com
Fri Mar 28 09:29:21 EDT 2008


With a.py containing this:

========== a.py ===========
#!/usr/bin/env python
import b

g = 0

def main():
    global g
    g = 1
    b.callb()

if __name__ == "__main__":
    main()
==========================

...and b.py containing...

========= b.py =============
import a, sys

def callb():
    print a.g
==========================

...can someone explain why invoking a.py prints 0?
I would have thought that the global variable 'g' of module 'a' would
be set to 1...



More information about the Python-list mailing list