interaction between modules... globals?

Brad Howes bradh at mediaone.net
Thu Jul 8 20:25:50 EDT 1999


Gerrit Holl <gerrit.holl at pobox.com> writes:

> I have a program which consists of several little modules, but I
> encounter a problem with that. I have one module which returns a
> class instance, with messages as members, either Dutch or
> English. Every module needs that instance, but I don't want to pass
> it as an argument to every little function, the modules should find
> out theirselves. But I _also_ don't want to make that instance 5
> times.
> 
> So I thougt: I need a sort of global between the modules. Is this possible?

This is what I've done before. Plop this at the bottom of the file
that define your class (`Singleton' below) and just import this module
everywhere else.

import __main__
if not hasattr( __main__.__builtins__, 'gMe' ):
    __main__.__builtins__.gMe = Singleton()






More information about the Python-list mailing list