software design question

Josiah Carlson jcarlson at nospam.uci.edu
Sun Feb 8 01:00:21 EST 2004


 From the sounds of your posts, you want your software to be "modular", 
in that you want have one file for each of the different components, but 
you don't want to spend the time to pass down all the proper references. 
  As a result, you want to have a single global namespace for all of 
your modules, so that you don't have to pass anything down.

There is another kludge:
#main.py
import x
import y

#make a copy of the dictionaries so that
xold = dict(x.__dict__)
yold = dict(y.__dict__)
x.__dict__.update(yold)
y.__dict__.update(xold)

x.xrunme()
y.yrunme()

#x.py
def xrunme():
     print "calling yrunyou"
     yrunyou()

def xrunyou():
     print "called xrunyou"

#y.py
def yrunme():
     print "calling xrunyou"
     xrunyou()

def yrunyou():
     print "called yrunyou"


In the above, you don't even need to import the sibling modules. 
Believe it or not, it works.

I would suggest you just put everything into a single file.  500 lines 
is not that large.  Heck, a few thousand isn't even that bad, as long as 
you pay attention to what you are doing and use an editor with a 
browsable source tree/class heirarchy, and comment liberally.

  - Josiah

P.S. For more stuff on this topic, check the thread with subject "Basic 
'import' problem", which has the same subjects pop up.



More information about the Python-list mailing list