Interpolation between multiple modules of an application.
Gerrit Holl
gerrit.holl at pobox.com
Wed Dec 15 08:45:23 EST 1999
Hello,
[see below for the raw, unexplained question]
I'm writing an application which consists of multiple modules. For example,
a common.py module, which defines the function:
# common.py
def nomain():
print "this file isn't meant to be executed,"
print "please run the file 'discoverb'"
# end
and then, every module uses this function. I end up with having the
following in *every* module:
import common
# ...
if __name__ == '__main__':
common.nomain()
# cut here
I also use the common module for other things.
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!
The only, UGLY solution I found is pickling it. UGLY!
So my question is:
How do I share session-depentent objects between modules, without them all
doing the same over and over again?
regards,
Gerrit.
--
"The IETF motto is 'rough consensus and running code'"
-- Scott Bradner (Open Sources, 1999 O'Reilly and Associates)
2:38pm up 34 min, 10 users, load average: 0.00, 0.00, 0.06
More information about the Python-list
mailing list