From 491dcabc5e30567d65907aafe80f102d2003a97e Mon Sep 17 00:00:00 2001 From: six Date: Sun, 11 Jan 2015 23:34:40 -0800 Subject: [PATCH 1/2] Decode bytes to str - os.read() returns bytes in Python 3. --- readchar/readchar_linux.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/readchar/readchar_linux.py b/readchar/readchar_linux.py index d96ec50..8701176 100644 --- a/readchar/readchar_linux.py +++ b/readchar/readchar_linux.py @@ -14,7 +14,8 @@ def readchar(wait_for_char=True): tty.setcbreak(sys.stdin.fileno()) try: if wait_for_char or select.select([sys.stdin, ], [], [], 0.0)[0]: - return os.read(sys.stdin.fileno(), 1) + char = os.read(sys.stdin.fileno(), 1) + return char if type(char) is str else char.decode() finally: termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings) return None From d0999202b04f66776b0aa566e691d8877499f856 Mon Sep 17 00:00:00 2001 From: six Date: Sun, 11 Jan 2015 23:39:42 -0800 Subject: [PATCH 2/2] return None is implicit --- readchar/readchar_linux.py | 1 - 1 file changed, 1 deletion(-) diff --git a/readchar/readchar_linux.py b/readchar/readchar_linux.py index 8701176..eb2c327 100644 --- a/readchar/readchar_linux.py +++ b/readchar/readchar_linux.py @@ -18,4 +18,3 @@ def readchar(wait_for_char=True): return char if type(char) is str else char.decode() finally: termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings) - return None