Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #61722
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'win32': 0.03; 'string.': 0.05; 'parsing': 0.09; 'try:': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'eof': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'nameerror:': 0.16; 'syntaxerror:': 0.16; 'unexpected': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'thanks.': 0.20; 'input': 0.22; 'cc:addr:python.org': 0.22; '2.x': 0.24; 'cc:2**0': 0.24; 'equivalent': 0.26; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'dec': 0.30; 'message- id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; '"",': 0.31; '13,': 0.31; '>>>>': 0.31; 'changes:': 0.31; 'safely': 0.31; 'file': 0.32; '(most': 0.33; 'beginning': 0.33; 'fri,': 0.33; 'except': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'that,': 0.38; 'recent': 0.39; 'called': 0.40; 'dangerous': 0.60; 'back': 0.62; 'more': 0.64; '2013,': 0.91; 'to:none': 0.92; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=Ynl7MjqnqnTwRPv6a+b9wZ+ZgFqUrH44JRm/iFvBC2Y=; b=z7+TYAxMtpnE7x7GdRwDcNCnSqTFYaq16aPO22CJadUzlfkYLxsY6dgC0clisAqGl5 j6Rm2xh6XMiL2aCZoR5X3Z2xE6fo4L6okyYQw6d6UM+1Sbc08R9xGKHKhlOtbG1lwjky 4VDCy3B2JeV52S1ZYCUUjQ33ZiE4i7GIsnq9riVV+MOhSrBHKK2diEXXokR6Q5dIqwQC sG5zXGuXJ6CMPJyOmjux95PWhS40hvDauSmgGybcjHywTN2S6mhqf7C1O+40x0hVdJWC Q76+ZtxY9c41XfFT6DZTDvLp53OuyJR01YoiMfxv5Hv903s27C2KQasNIQcZ7PtBXMR4 OLcg== |
| MIME-Version | 1.0 |
| X-Received | by 10.68.108.194 with SMTP id hm2mr150133pbb.22.1386860014721; Thu, 12 Dec 2013 06:53:34 -0800 (PST) |
| In-Reply-To | <2ba69b81-99f9-40d6-a337-afb2f892ecff@googlegroups.com> |
| References | <2ba69b81-99f9-40d6-a337-afb2f892ecff@googlegroups.com> |
| Date | Fri, 13 Dec 2013 01:53:34 +1100 |
| Subject | Re: input() on python 2.7.5 vs 3.3.2 |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3996.1386860018.18130.python-list@python.org> (permalink) |
| Lines | 39 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1386860018 news.xs4all.nl 2842 [2001:888:2000:d::a6]:44728 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:61722 |
Show key headers only | View raw
On Fri, Dec 13, 2013 at 1:45 AM, <stephen.boulet@gmail.com> wrote:
> Can someone explain? Thanks.
>
> Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>>>> x = input()
> Hello there
>>>> print(x)
> Hello there
>
> Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>>>> x = input()
> Hello there
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "<string>", line 1
> Hello there
> ^
> SyntaxError: unexpected EOF while parsing
It's very simple: The input() function in Python 2.x is a very
dangerous one - it's equivalent to eval(input()) in Python 3. The
equivalent function in Python 2 is called raw_input. For safety and
compatibility, just do this at the beginning of your interactive
session or the top of your script:
input = raw_input
or, in a way that'll work in Python 3 as well, with no changes:
try:
input = raw_input
except NameError:
pass
After that, you can safely call input() and get back a string.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
input() on python 2.7.5 vs 3.3.2 stephen.boulet@gmail.com - 2013-12-12 06:45 -0800 Re: input() on python 2.7.5 vs 3.3.2 Chris Angelico <rosuav@gmail.com> - 2013-12-13 01:53 +1100 Re: input() on python 2.7.5 vs 3.3.2 Amit Saha <amitsaha.in@gmail.com> - 2013-12-13 00:56 +1000 Re: input() on python 2.7.5 vs 3.3.2 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-12 15:04 +0000 Re: input() on python 2.7.5 vs 3.3.2 Chris Angelico <rosuav@gmail.com> - 2013-12-13 02:17 +1100
csiph-web