Polymorphing - how?

Fernando Pérez fperez528 at yahoo.com
Wed May 1 16:52:53 EDT 2002


delete .PL wrote:

> I would like to execute functions which names will be changed during
> runtime. The following approach does not work. :-(
> 
> def First(s):
>         print "myFun1: %s" % s
> def Second(s)
>         print "myFun2: %s" % s
> name = 'First'
> 

name = First

Functions are first-class objects in Python, you can assign them to a variable 
just like anything else.

Cheers,

f.



More information about the Python-list mailing list