global variable scope
Laura Creighton
lac at strakt.com
Sat Feb 8 22:26:16 EST 2003
> Is it possible to make a variable "super-global", meaning that it is
> visible to *all* modules of a python program (I'm well aware of the
> pitfalls to such techniques)?
> --
Approach 1. Have a module within the package whose purpose is to maintain
your state, and let the other modules simply import it to
access the state via whatever mechanism you want to provide.
Approach 2. Place the package wide state in __init__.py. Make the
individual package modules import their own package to
access or change it. Don't name any individual module
the same as your package name. Now you have a dependency
in every module on the overall package name.
Approach 3. import __builtin__ and assign something to
__builtin__.SuperGlobal (or whatever you call it). This is
considered even more dirty.
Laura
More information about the Python-list
mailing list