input() on python 2.7.5 vs 3.3.2

Chris Angelico rosuav at gmail.com
Thu Dec 12 10:17:52 EST 2013


On Fri, Dec 13, 2013 at 2:04 AM, Mark Lawrence <breamoreboy at yahoo.co.uk> wrote:
> I much prefer Chris Angelico's response "The input() function in Python 2.x
> is a very dangerous one - it's equivalent to eval(input()) in Python 3."

Just to clarify: If you *want* eval, then you know you want it, and
you are (or should be) aware of its dangers. The problem, imo, is
hiding something as powerful and dangerous as code evaluation behind
the innocuous name "input". If I were coding a Python 2.x REPL, I
would probably write eval(raw_input()) rather than input(), just for
clarity.

But I'm more likely to just code for Python 3 anyway. :)

ChrisA



More information about the Python-list mailing list