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


Groups > comp.lang.python > #26402

Re: consistent input() for Python 2 and 3

Date 2012-08-02 13:07 +0200
From Philipp Hagemeister <phihag@phihag.de>
Subject Re: consistent input() for Python 2 and 3
References <72vpe9-kki.ln1@satorlaser.homedns.org>
Newsgroups comp.lang.python
Message-ID <mailman.2870.1343905697.4697.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On 08/02/2012 11:49 AM, Ulrich Eckhardt wrote:
>   try:
>       # redirect input() to raw_input() like Python 3
>       input = raw_input
>   except NameError:
>       # no raw input, probably running Python 3 already
>       pass
> What do you think? Any better alternatives?

That's the generic solution, see
http://python3porting.com/differences.html#input-and-raw-input .

In my experience, it seems that input's main function is to allow
beginners to learn the language, or to be used in short scripts. For a
serious application, either curses or moving the input to the invocation
arguments is often a better choice.

- Philipp

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


Thread

consistent input() for Python 2 and 3 Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-08-02 11:49 +0200
  Re: consistent input() for Python 2 and 3 Philipp Hagemeister <phihag@phihag.de> - 2012-08-02 13:07 +0200

csiph-web