absolute namespace for callbacks?

Werner Schiendl ws-news at gmx.at
Tue Mar 6 11:59:26 EST 2001


Con you specify how you intend to register your callback?

somewhat like this?

>>> def test_func(msg):
...  print "Hello in Testfunc, message is:", msg
...  return len(msg)
...
>>> def use_callback(func):
...  print "Function provided as callback is %s", func
...  testdata = "Hello, World!"
...  result = func(testdata)
...  print "Invoked function with %s, result is %d" % (testdata, result)
...  return result
...
>>> use_callback(test_func)
Function provided as callback is %s <function test_func at 0146CBBC>
Hello in Testfunc, message is: Hello, World!
Invoked function with Hello, World!, result is 13
13

(make sure for proper identation)

So it in fact does not matter, where test_func or use_callback is
declared...
Did I miss something?

hth
werner


Bruce Edge <bedge at troikanetworks.com> wrote in message
news:3AA51144.3DD3FC3F at troikanetworks.com...
> My callback func is defined in one module, and the callback is executed
> from another module which does not know in advance what module the
> callback func resides in. So, by default, the caller cannot find the
> callback func in it's own namespace.
> The callback registration procedure needs to specify the namespace where
> the callback func exists.
>
> OTOH, maybe I'm missing something here :-)
>
> -Bruce.
>
> Werner Schiendl wrote:
> >
> > What's the matter?
> >
> > You do not pass the name, but a reference to the function
> > (the function is an object for python like anything else)
> > It does not matter where the function is defined...
> >
> > or did I miss anything in your post?
> >
> > hth
> > werner
> >
> > Bruce Edge <bedge at troikanetworks.com> wrote in message
> > news:3AA50AFB.83C7459F at troikanetworks.com...
> > > Tcl has a func to get a fully qualified namespace from a context. This
> > > is essential for registering callback functions.
> > > How does one register a callback in Python, when the callback func
> > > exists in a different namespace?
> > >
> > > Is there any method to get the current absolute namespace?
> > >
> > > Thanks, Bruce.
> > >





More information about the Python-list mailing list