[Tutor] Exec? [was comparative code questions]

Gonçalo Rodrigues op73418@mail.telepac.pt
Wed Jan 15 10:39:14 2003


----- Original Message -----
From: "Tim Johnson" <tim@johnsons-web.com>
To: <tutor@python.org>
Sent: Wednesday, January 15, 2003 2:45 AM
Subject: [Tutor] Exec? [was comparative code questions]


> I'm looking at page 456 in "The Python Cookbook"
> I quote as follows:
>
> "The exec statement is a last-ditch measure, to be used only
>  when nothing else is available (which is basically never)"
>
>  Do I understand from the above that 'exec' should not
>  be used?

No. Others have already given the reasons for mistrusting exec and eval. I
will give you one situation where it is reasonable to use it: suppose you
have a Python application and want to extend it by adding a scripting
language. Since the application is already in Python, and the interpreter is
always available, just use Python as the scripting language via exec.

>
>  TIA
>  tim
>

All the best,
G. Rodrigues