Python Global State

er erobererunc at
Tue Feb 3 14:10:18 EST 2009

That was my hack for one other app, but I did it because I'd only been
studying Python for a month or two.  Glad to see others did it once as well,
but that we all wised up.  =P

It might be nice if Python could provide a global dictionary, perhaps _G{},
where you can throw things.  This is actually the solution provided by the
Lua scripting language.  Thanks for the global_ module solution, I was just
making sure that was the canonical way.

On Tue, Feb 3, 2009 at 1:27 PM, <rdmurray at> wrote:

> Quoth MRAB <google at>:
> > 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.
> --
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list