callback confusion

Donn Ingle donn.ingle at gmail.com
Sat Dec 8 11:36:05 EST 2007


Hi,
I have two modules, the second is imported by the first.
Let's call them one.py and two.py (two being my API)

In the first I register a function into the second.
[in one.py]
def boo(): ...
...
two.register( boo )

two.startLoop()

In two.py it starts a loop (GTK timeout), so processing remains there.
At some point it's time to call the callback.

[within the loop in two.py]
f = getFunc()
f()

That works, it calls boo( ) in one.py -- all fine. The thing I can't figure
out is that it's calling it from the namespace p.o.v of two.py -- For
example:

[in one.py]
kills=0
def boo():
 print kills

It will abort with:
    print kills
UnboundLocalError: local variable 'kills' referenced before assignment

How can I get the 'self' of a module? If I could tell it to [print
moduleself.kills] or something like that I'd be in business again. 
 It would be best to have no funny stuff on the user-end of the API; a
simple [print kills] would be best.

\d




More information about the Python-list mailing list