Interpolation between multiple modules of an application.

Fredrik Lundh fredrik at pythonware.com
Wed Dec 15 09:28:46 EST 1999


Gerrit Holl <gerrit.holl at pobox.com> wrote:
> This isn't really bad, but consider the language.py module; it defines
> a Class like this:
> 
> # language.py (untested code)
> 
> import userdict
> 
> class Language(userdict.userdict):
>     def __init__(self, lang):
>         self.data = {...} # define self.data
> 
> Every module needs to print messages, so *every* module imports language and
> *every* module created a class so *every* time a file is parsed! That's wrong!

yes, that's wrong.  the "import" statement only reads
the module and creates the class once -- the first time
you import the module.

see "What Does Python Do to Import a Module?" on
http://www.pythonware.com/people/fredrik/fyi/fyi06.htm
for more info (and the one exception to the above rule).

> How do I share session-depentent objects between modules, without them all
> doing the same over and over again?

create them once, on the module level.  that's all
you need to do.

</F>





More information about the Python-list mailing list