Passing Global Variables between imported modules

John J. Lee jjl at pobox.com
Mon Aug 4 14:11:36 EDT 2003


sean at activeprime.com (Sean) writes:

> Is there any way to access global variables defined from within an
> imported module?  For example, lets say have a file called test2.py
> that defines a simple class:
[...]
> Now I have another file that imports test2, sets a global variable
> called globalVar, and calles printGlobal() like so:
[...]

You could explicitly pass MyClass constructor the globals dict
(globals()), and have it use that.  Not very nice.

What's your end goal with this, though?

Why not have a class to represent this 'global' state (since it seems
it isn't really global)?


John




More information about the Python-list mailing list