How to have application-wide global objects

Jeremy Sanders jeremy+complangpython at jeremysanders.net
Fri Jul 14 06:00:27 EDT 2006


Fredrik Lundh wrote:

> no, the "bar.py" *file* gets loaded twice, first as the "foo.bar"
> module, and then as the "bar" module.

True and I agree with your email, but suppose there is bar1.py and bar2.py
in foo, then they can refer to each other by importing bar2 and bar1,
respectively. These module objects will be the same modules that test.py
would get by importing foo.bar1 and foo.bar2.

By analogy you might expect the path munging example to work, but the
details are in the nitty-gritty of how python importing works. The import
docs say something like "Details of the module searching and loading
process are implementation and platform specific". The results can be a
little suprising! It would be include a check so that you could get a
warning with debugging switched on.

-- 
Jeremy Sanders
http://www.jeremysanders.net/



More information about the Python-list mailing list