Injecting a global into a defined function??

C

Cong Ma

Hi,

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
example:

@global_injected("SPAM")
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.

Regards,
Cong.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top