[Python-ideas] List Revolution

Guido van Rossum guido at python.org
Sat Sep 10 23:35:57 CEST 2011

On Sat, Sep 10, 2011 at 12:07 PM, Massimo Di Pierro
<mdipierro at cs.depaul.edu> wrote:
> Not to open a can of worms but why not use eval in this example?
> It is faster. It is 5x more compact. It allows me to take advantage of the Python parser instead of reinventing the wheel. It is less error prone and easier to understand. It is a python keyword.

It is unsafe (as the bug in your first version inadvertently illustrated :-).

I don't actually quite follow what your example does (sorry), but,
even though it is less powerful than exec(), eval() invokes the full
Python parser+compiler, which can take quite a bit of time to start up
and uses a fair bit of memory. Also in other Python versions this is
often much slower than in CPython, or has a big startup overhead.

But, of course, it is great for quick demos!

--Guido van Rossum (python.org/~guido)

More information about the Python-ideas mailing list