Call a function using a variable

Andrew Dalke dalke at acm.org
Fri Apr 27 17:15:57 EDT 2001


Colin Meeks asked:
>Does anybody know if it's possible to do something along the following
lines
>:
>
>myfunction="test"
>x=myfunction

>>> def test(): print "Testing!"
...
>>> myfunction = globals()["test"]
>>> myfunction()
Testing!
>>>

                    Andrew
                    dalke at acm.org






More information about the Python-list mailing list