python2 input

Chris Angelico rosuav at gmail.com
Fri May 3 03:31:59 EDT 2013


On Fri, May 3, 2013 at 5:16 PM, dabaichi <valbendan at outlook.com> wrote:
> Hello guys:
> Do you have found that the built-in input() function is dangerous.
> Here is my code(python 2.x only):
>
> a = input("Input anything:")
> print("go here")
>
> If I input:
> sys.exit(0)
> print("go here") will not be execute, and the script will exit.

Yeah, that's kinda discovered. In Python 2, you should be using
raw_input() for that kind of thing. In Python 3, raw_input() was
renamed to input(), and if you want the semantics of Py2 input(), it's
eval(input()), which makes it obvious what's going on.

ChrisA



More information about the Python-list mailing list