sharing data between modules
Bruce Edge
bedge at troikanetworks.com
Fri Mar 23 12:52:49 EST 2001
In article <99fvbq$mmg$1 at panix3.panix.com>, "Aahz Maruch" <aahz at panix.com>
wrote:
> In article <20010323.073801.76065818.26070 at mead.troikanetworks.com>,
> Bruce Edge <bedge at troikanetworks.com> 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 globals.py if variables are
> shared across multiple classes or set variables in your class modules if
> it's specific to a single class.
global.py! Argh, it so simple, why didn't I think of that.
Probably because my sum total experience with python is almost a month
:-)
Thank you! That makes my life much easier (and my code smaller).
-Bruce.
More information about the Python-list
mailing list