Can Python do this?

Giorgi Lekishvili gleki at gol.ge
Tue Mar 5 17:26:11 EST 2002


Hi!

Can you tell me little bit more why is this a bad idea to use exec/eval?
Where can I find more information?

Thank you in advance.
Greetings,
Giorgi

Gerhard Häring wrote:

> Le 04/03/02 à 12:51, Robert Oschler écrivit:
> > Hello, Python newbie here.
> >
> > Let's say I'd like to build a method name into a string variable (e.g.
> > "FuncCall" + "1" to attempt to call "FuncCall1").  Can I then call that
> > method by somehow having the interpreter evaluate the string variable into a
> > call to the desired method? (I know this is usually done in a language like
> > Prolog or Lisp but I'm hoping Python can do it too.)
>
> This can easily be done with the built-ins eval and exec. But in 99 % of
> all cases, it's a really bad idea to use them. Perhaps you can tell us
> what you're trying to accomplish anyway? There's usually a better way
> than (ab)using eval/exec.
>
> Gerhard
> --
> This sig powered by Python!
> Außentemperatur in München: 5.7 °C      Wind: 2.1 m/s




More information about the Python-list mailing list