How do I display the "Press ENTER to continue" in Python 3.4?

6

I wanted to know how to do the " Press ENTER to continue", or the " Press any key to continue " in Python 3.4 without having to create a variable just to store the ENTER.

    
asked by anonymous 18.06.2015 / 04:18

3 answers

5

Just do not save the input result to a variable

input("Pressione ENTER para continuar")
    
18.06.2015 / 04:46
1

To require Enter (ie ignore everything the user types until Enter is pressed), see hugomg's answer . Already in the case of accepting any key (ie returning whatever the user has typed, without waiting for Enter ) this question in SOen shows an implementation of getch in Python. One of its versions is:

def _find_getch():
    try:
        import termios
    except ImportError:
        # Non-POSIX. Return msvcrt's (Windows') getch.
        import msvcrt
        return msvcrt.getch

    # POSIX system. Create and return a getch that manipulates the tty.
    import sys, tty
    def _getch():
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(fd)
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch

    return _getch

getch = _find_getch()

When using, you can ignore the return value if you want, but you must print the initial message separately:

def anykey(msg='Pressione qualquer tecla para continuar'):
    print(msg)
    getch()
    
18.06.2015 / 08:16
0

Let's try to do this by finishing the current process and showing the message "Press any key to continue ..." native system:

import subprocess
subprocess.check_call([r"C:\Windows\System32\cmd.exe", "/c PAUSE"])

will run the command pause native MS-DOS, showing with system-based language.

    
25.07.2015 / 20:23