consistent input() for Python 2 and 3

Philipp Hagemeister phihag at phihag.de
Thu Aug 2 07:07:59 EDT 2012


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20120802/49ad37a6/attachment.sig>


More information about the Python-list mailing list