Polymorphing - how?
Sean 'Shaleh' Perry
shalehperry at attbi.com
Wed May 1 16:56:06 EDT 2002
On 01-May-2002 Jaros³aw Zabie³³o 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('blah') # It doesn't work. :-(
> # TypeError: 'str' object is not callable
> name = 'Second'
> name('blah') # Like above.
>
name = First
name('blah')
name = Second
name('blah')
will work. otherwise you need to exec the string.
More information about the Python-list
mailing list