Maybe use sys.stdin.read when starting up in PyDev? for example, sys.stdin.read(1) read 1 line from the input ... For use in the Windows console and PyDev, make the same choice based on the os and run options (using sys.stdin.isatty ). For example, the following code reads user input. But when launched in the Windows console, if the standard input code of the program is connected to another software standard, then sys.stdin.isatty returns False and enters reading using sys.stdin.read , and not msvcrt.getch :
import sys, time import platform if platform.system() == "Windows": import msvcrt else: from select import select def input_with_timeout_sane(prompt, timeout, default): """Read an input from the user or timeout""" print prompt, sys.stdout.flush() rlist, _, _ = select([sys.stdin], [], [], timeout) if rlist: s = sys.stdin.readline().replace('\n','') else: s = default print s return s def input_with_timeout_windows(prompt, timeout, default): start_time = time.time() print prompt, sys.stdout.flush() input = '' read_f=msvcrt.getche input_check=msvcrt.kbhit if not sys.stdin.isatty( ): read_f=lambda:sys.stdin.read(1) input_check=lambda:True while True: if input_check(): chr_or_str = read_f() try: if ord(chr_or_str) == 13:
lolipop
source share