Difference between eval and exec ??

Jeff Shannon jeff at ccvcorp.com
Tue Mar 26 13:59:46 EST 2002


Thomas Weholt wrote:

> Eval and exec seem to have the same effect. What's the real difference?
>
> In this case : docs != enlightenment.

Raymond Hettinger already answered the question you asked, but I'll stick
my nose in and add another comment.

Yeah, they do both seem to have the same effect -- they both mislead people
into thinking that they're a good shortcut, when in reality, 99.99% of the
time that you might reach for exec/eval(), there's a cleaner, safer,
*better* way of doing things.  Both should come with clear warnings, "For
Emergency Use Only!!"

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list