absolute namespace for callbacks?

Darren New dnew at san.rr.com
Tue Mar 6 18:31:49 CET 2001

> How does one register a callback in Python, when the callback func
> exists in a different namespace?

Knowing both Tcl and a little Python, I think I understand your confusion.

In Tcl, you pass the name of the function to be called, as a string. The
interpreter does not know, at the time of creating the callback, that it's
actually the name of a function. Hence, it needs to be "fully qualify"
namespace-wise in order for the interpreter to map from the function name to
the function body when the callback invokes it.

In Python, you pass (essentially) a pointer to the function itself. That is,
the widget is storing the address of the function to be invoked in its local
variables, rather than the name of the function. The function is an object
(in the OO sense) so it knows its own namespace and can get to its locals
thru pointers embedded in the function object itself. 

(Modulo oversimplification, of course.)

Darren New / Senior MTS & Free Radical / Invisible Worlds Inc.
San Diego, CA, USA (PST).  Cryptokeys on demand.

More information about the Python-list mailing list