sharing data between modules

Aahz Maruch aahz at
Fri Mar 23 17:58:34 CET 2001

In article <20010323.073801.76065818.26070 at>,
Bruce Edge <bedge at> wrote:
>As a C++ guy I tend to put each class in a different file. In python this
>gives me a different module for each class. My app uses this group of
>classes, ie: modules, what's the best way to share data between them?
>Currently I register the classes with each other using class static data, 
>so they all have a reference to each other. Ideally, I'd like to be able
>to have a few globals that every module can see.  

If you're sharing instance data, references are the best way to go.  If
it's truly global data, one of the advantages of Python modules is that
they *are* namespaces.  So either create a if variables are
shared across multiple classes or set variables in your class modules if
it's specific to a single class.
                      --- Aahz  <*>  (Copyright 2001 by aahz at

Androgynous poly kinky vanilla queer het Pythonista
Hugs and backrubs -- I break Rule 6

"I won't accept a model of the universe in which free will, omniscient
gods, and atheism are simultaneously true."  -- M

More information about the Python-list mailing list