[Python-Dev] LOAD_NAME & classes

Aahz aahz@pythoncraft.com
Tue, 23 Apr 2002 14:13:14 -0400


On Tue, Apr 23, 2002, Michael Gilfix wrote:
>
>   Has there ever been a discussion about some easy or straight-forward
> way of sharing a global instance across modules? For example, in a
> gui app, you might want to structure the program such that there's a
> global instance app (main.app) of the application that other modules
> might want to query. I was never to happy with importing main and then
> using main.app... I felt like I wanted to qualify it as a global, like:
> 
>   from main import global app

The simple way to do it, IMO, is to import a joint module, called
something like cfg.  I just did a little hack in a script with

    cfg = imp.new_module('cfg')

but I don't know how well that works across modules.  I think you'd need
to poke it into sys.modules in order for it to be shared, but I haven't
tested it.
-- 
Aahz (aahz@pythoncraft.com)           <*>         http://www.pythoncraft.com/

What if there were no rhetorical questions?