Injecting a global into a defined function??

Cong Ma cma at
Thu Jan 15 19:28:35 CET 2009


I'd appreciate your hints on this problem. I'm writing a module in which several
functions can alter the value of a global variable (I know this sounds evil,
please forgive me...). What I'm trying to do is to eliminate the "global foo"
lines in those functions' bodies and to use a decorator for the same task. For

    def foo():
        ... ...

will have the same effect as

    def foo():
        global SPAM
        ... ...

Leaving the evilness of globals aside, I wonder how I can implement this (for
Python 2.x). I'd like to hear your opinions. Thank you.


More information about the Python-list mailing list