''' I'm in the middle of a refactoring dilemma. I have several singletons that I'm turning into modules, for ease of access. The usual method is noted as 'Module 1' below. The new method is noted as 'Module 2'. Is there any reason NOT to do this that I may be unaware of? It's easier than remembering to declare global variables at the top of the function. '''
# ----------- Module 1.py ------------ # Normal module processing var = 0 def MyRoutine(): global var var = 1 MyRoutine() print var # ----------- Module 2.py ------------ # 'Self' module processing import sys var = 0 self = sys.modules[__name__] def MyRoutine(): self.var = 1 MyRoutine() print var -- http://mail.python.org/mailman/listinfo/python-list