calling variable function name ?

Arnaud Delobelle arnodel at googlemail.com
Tue Apr 8 15:56:38 EDT 2008


On Apr 8, 8:52 pm, TkNeo <tarun.... at gmail.com> wrote:
> I don't know the exact terminology in python, but this is something i
> am trying to do
>
> i have 3 functions lets say
> FA(param1,param2)
> FB(param1,param2)
> FC(param1,param2)
>
> temp = "B" #something entered by user. now i want to call FB. I don't
> want to do an if else because if have way too many methods like
> this...
>
> var = "F" + temp
> var(param1, param2)
>
> This does not work ofcourse. Does anyone know how to implement this ?

F = { 'A': FA, 'B':FB, 'C':FC }

F['A'](param1, param2)

HTH

--
Arnaud




More information about the Python-list mailing list