Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #26394
| From | Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | consistent input() for Python 2 and 3 |
| Date | 2012-08-02 11:49 +0200 |
| Message-ID | <72vpe9-kki.ln1@satorlaser.homedns.org> (permalink) |
Hi!
I'm trying to write some code that should work with both Python 2 and 3.
One of the problems there is that the input() function has different
meanings, I just need the raw_input() behaviour of Python 2.
My approach is to simply do this:
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?
Uli
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll 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