dynamic call of a function

Michael Hudson mwh at python.net
Fri Oct 19 05:00:02 EDT 2001


anthony harel <anthony.harel at c-s.fr> writes:

> I have got a string that contains the name of the function I
> want to call but I don't want to do something like this :
[schnipp]
> Is it possible to do sommething like that :
> ch = "foo"
> apply(ch, ( ))???

Well, there's 

eval(ch)()

but that's rather horrible.

vars()[ch]()

is, possibly, better.

More context please.  What are you really trying to do?

Cheers,
M.

-- 
  ZAPHOD:  You know what I'm thinking?
    FORD:  No.
  ZAPHOD:  Neither do I.  Frightening isn't it?
                   -- The Hitch-Hikers Guide to the Galaxy, Episode 11



More information about the Python-list mailing list