[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Refactoring Dilemma
From:       "Kamilche" <klachemin () comcast ! net>
Date:       2006-09-10 17:37:19
Message-ID: 1157909839.595690.183090 () p79g2000cwp ! googlegroups ! com
[Download RAW message or body]

'''
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
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic