How to initialize a class variable once
Brian Allen Vanderburg II
BrianVanderburg2 at aim.com
Tue Dec 9 12:31:12 CET 2008
mccredie at gmail.com wrote:
> Unless you are calling reload() on the module, it will only ever get
> _loaded_ once. Each additional import will just yield the existing
> module. Perhaps if you post an example of the behavior that leads you
> to believe that the class variables are getting reinitialized I can
> provide more useful help.
There is one situation where a module can be imported/executed twice, if
it is the __main__ module. Obviously the example below would be
considered bad Python practice but it just shows how it can be done:
if __name__ == "__main__":
blah = main.Blah()
The reason is the first time main.py gets loaded, it is known as
'__main__' but when app imports main, it is not in sys.modules so it
loads 'main.py' again but this time as 'main'
Brian Vanderburg II
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list