dynamic call of a function

Michael Hudson mwh at python.net
Fri Oct 19 05:43:24 EDT 2001


Michael Hudson <mwh at python.net> writes:

> 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.

Oops, I read your english and not your code.  What Graham and Paul
said applies better.  functions aren't quite the same as methods in
Python...

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

This might still be relavent.

Cheers,
M.

-- 
  LINTILLA:  You could take some evening classes.
    ARTHUR:  What, here?
  LINTILLA:  Yes, I've got a bottle of them.  Little pink ones.
                   -- The Hitch-Hikers Guide to the Galaxy, Episode 12



More information about the Python-list mailing list