Python Global State

rdmurray at bitdance.com rdmurray at bitdance.com
Tue Feb 3 19:27:33 CET 2009


Quoth MRAB <google at mrabarnett.plus.com>:
> er wrote:
> > Simple question, I think: Is there a way to make a completely global
> > variable across a slew of modules?  If not, what is the canonical
> > way to keep a global state?  The purpose of this is to try to prevent
> > circular module imports, which just sort of seems nasty.  Thank you!
> > 
> Simple answer: no.

I'm wondering a little about posting this, but...well, the answer actually
isn't "no".  It's just that it's not something you should _ever_ do.
The trick is to assign the value to the __builtins__ module...

--RDM

PS: I know this because Zope used to do it.  Fortunately they wised
up and refactored that code to be more sane.




More information about the Python-list mailing list