How to initialize a class variable once

Joe Strout joe at
Tue Dec 9 16:36:50 CET 2008

On Dec 9, 2008, at 4:31 AM, Brian Allen Vanderburg II wrote:

> There is one situation where a module can be imported/executed  
> twice, if it is the __main__ module.

That's an excellent point -- this is something I've run into, and it  
always feels a bit awkward to code around it. What's the standard  
idiom for avoiding this issue in a complex app?  Have a "main" file  
that is not imported by anything else, and which does little but  
launch stuff from some other module?

As I say it, that seems obvious, but somehow I keep getting urges to  
put global stuff (like my Application subclass) in the main file, and  
then I find I need to reference it from some other module, and get  
into trouble.  This is probably just bias from my last programming  
environment, though.  I can adapt.

Anyway, thanks for pointing this out; I bet it's the root cause of the  
OP's observation.

- Joe

More information about the Python-list mailing list