By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,767 Members | 1,987 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,767 IT Pros & Developers. It's quick & easy.

Real globals inside a module

P: n/a
Hi All,

I am wrestling with some architecture inside my app. Let's say I have
a tunings collection, which contains e.g. 23 types of guitar tunings.
In my song object I want to restore a relation between one of the
tuning objects inside the tunings module.

I already figured out I need somethign like a global collection inside
the tunings module,. but how global is it? When I am inside my app
object, and import the tunings module, can I access the same global
class as when I am inside my songs module and load the tunings module?

So for some pseudo code:

--- songs.py

import tunings

class Song(object):
def __init__(self, tuning_id):
# create relation with tuning object
self._tuning = tunings.GetTuningById(tuning_id)

-- app.py

import tunings

# get list of tunings

for t in tunings._tuningCollection:
print 'Tuning:', t._name

----

So basically I want to access the same global list in both modules,
but not re-create the list in every module since it should be restored
by the database layer once.

Is this as simple as defining a global variable in the module tunings
which is available on both imports, or should I do it different, and
then my next question ofcourse is, how ? :-)

Thanks for any advice, I do not want to make a global manager object
that I need to pass around all the time, that would be silly..

Regards,
- Jorgen
May 13 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.