How to assign a function to another function

Stefano Esposito stefano.esposito87 at gmail.com
Mon Sep 17 13:11:16 EDT 2007


On Mon, 17 Sep 2007 17:49:58 +0100
Paul Rudin <paul.nospam at rudin.co.uk> wrote:

> Stefano Esposito <stefano.esposito87 at gmail.com> writes:
> 
> > Hi all
> >
> > what i'm trying to do is this:
> >
> >>>>def foo ():
> > ...	return None
> > ...
> >>>>def bar ():
> > ...	print "called bar"
> > ...
> >>>>def assigner ():
> > ...	foo = bar
> > ...
> >>>>assigner()
> >>>>foo()
> > called bar
> >>>>
> >
> > This piece of code is not working and even trying with...
> 
> 
> > ... How can I achieve my goal?
> 
> 
> By adding the line:
>    global foo
> at the beginning of the body of assigner.
> 

This worked, thanks a lot :)


-- 
Stefano Esposito <stefano.esposito87 at gmail.com>



More information about the Python-list mailing list