Refactoring Dilemma
Steven Bethard
steven.bethard at gmail.com
Mon Sep 11 09:59:23 EDT 2006
Kamilche wrote:
> Is there any reason NOT to do this that I may be unaware of?
[snip]
> # ----------- Module 2.py ------------
> # 'Self' module processing
> import sys
> var = 0
> self = sys.modules[__name__]
>
> def MyRoutine():
> self.var = 1
>
> MyRoutine()
> print var
Looks basically fine to me, but I'd probably write it as::
_self = __import__(__name__)
Then you don't need to import sys. I'd also use a leading underscore
for "self" so that it's clearly marked as a module-internal attribute.
STeVe
More information about the Python-list
mailing list