On 9/17/07, Stefano Esposito <[EMAIL PROTECTED]> wrote:
> Hi all
>
> what i'm trying to do is this:
>
> >>>def foo ():
> ...     return None
> ...
> >>>def bar ():
> ...     print "called bar"
> ...
> >>>def assigner ():
> ...     foo = bar
> ...

You need to tell "assigner()" that foo doesn't belong to the local
(function) namespace, but rather comes from the global namespace:

In [1]: def foo():
   ...:     return None
   ...:

In [2]: def bar():
   ...:     print "called bar"
   ...:
   ...:

In [3]: def assigner():
   ...:     global foo
   ...:     foo = bar
   ...:
   ...:

In [4]: assigner()

In [5]: foo()
called bar

Kurt
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to