This works on Ubuntu 8.04.1, Python 2.5.2, I do not get such an error. Maybe you should try it from the command line, eclipse can use its own stdin, I get the same error if I run it from the Wing IDE, but from the command line it works fine. The reason is that the IDE, for example, Wing uses its own class netserver.CDbgInputStream as sys.stdin so sys.stdin.fileno is zero, which is why the error. Basically the IDE stdin is not tty (print sys.stdin.isatty () is False)
class _GetchUnix: def __init__(self): import tty, sys def __call__(self): import sys, tty, termios fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) try: tty.setraw(sys.stdin.fileno()) ch = sys.stdin.read(1) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) return ch getch = _GetchUnix() print getch()
source share