What for a file that prints nothing - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: What for a file that prints nothing (/thread-12783.html) |
What for a file that prints nothing - sylas - Sep-12-2018 Hi all ! I have this file that prints nothing. How to modify in order to see something ?? class _Getch: """Gets a single character from standard input. Does not echo to the screen.""" def __init__(self): try: self.impl = _GetchWindows() except ImportError: self.impl = _GetchUnix() def __call__(self): return self.impl() 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 class _GetchWindows: def __init__(self): import msvcrt def __call__(self): import msvcrt return msvcrt.getch() getch = _Getch()#origin #char = getch.getche() # also displayed on the screen #char = _Getch() # also displayed on the screen RE: What for a file that prints nothing - gruntfutuk - Sep-12-2018 That's a pretty old library, and doesn't work on macOS (just tried it). You might want to look at a more recent alternative (which I think might be based on the ActiveState recipe you shared). readchar 2.0.1 on PyPi I tried it in the shell, and it worked fine with this code: import readchar while True: key = readchar.readkey() if key == " ": breakObviously, I could print whatever character was read (assuming it was printable character). |