Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #44658

Re: python2 input

References <klvo0t$2blv$1@adenine.netfront.net>
Date 2013-05-03 17:31 +1000
Subject Re: python2 input
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1264.1367566322.3114.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, May 3, 2013 at 5:16 PM, dabaichi <valbendan@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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

python2 input "dabaichi" <valbendan@outlook.com> - 2013-05-03 15:16 +0800
  Re: python2 input Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-03 07:29 +0000
  Re: python2 input Chris Angelico <rosuav@gmail.com> - 2013-05-03 17:31 +1000

csiph-web