Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a way to use input("Press any key to continue") on version 2.6

Tags:

python

input

I want the program to pause and wait until you press any key to continue, but raw_input() is going away, and input() is replacing it. So I have
var = input("Press enter to continue") and it waits until I press enter, but then it fails with SyntaxError: unexpected EOF while Parsing. This works OK on a system with Python 3, but this is linux Python 2.6 and I hate to have to code in raw_input() since it is going away. Any suggestions?

like image 844
Dag Avatar asked Nov 04 '10 03:11

Dag


3 Answers

Use this

try:
    input= raw_input
except NameError:
    pass

If raw_input exists, it will be used for input. If it doesn't exist, input still exists.

like image 143
S.Lott Avatar answered Nov 15 '22 00:11

S.Lott


you could do something on the line of ...

def myinput(prompt):
    try:
        return raw_input(prompt)
    except NameError:
        return input(prompt)

... but don't.

Instead, just use raw_input() on your program, and then use 2to3 to convert the file to python 3.x. That will convert all the raw_input()s for you and also other stuff you might be missing.

That's the recommended way to keep a software working on both python 2 and python 3 and also keep sanity.

like image 20
nosklo Avatar answered Nov 14 '22 22:11

nosklo


import os
os.sys('pause') 

You can use this module on Windows.

like image 45
River Mountain Avatar answered Nov 14 '22 23:11

River Mountain