Call a function using a variable
Sean 'Shaleh' Perry
shaleh at valinux.com
Fri Apr 27 16:34:40 EDT 2001
On 27-Apr-2001 Bjorn Pettersen wrote:
>> From: Colin Meeks [mailto:colinmeeks at home.com]
>>
>> Does anybody know if it's possible to do something along the
>> following lines
>> :
>>
>> myfunction="test"
>> x=myfunction
>>
>> Basically what I want is when the x variable gets declared it
>> get's it's
>> data from the function test()
>
> myfunction = eval('test')
> x = myfunction()
>
> of course, if you're not sure what you're passing to eval you might get
> surprising results <wink>
>
my question is why use a string? You can just use the function itself:
myfunc = existing_func
x = myfunc()
More information about the Python-list
mailing list