Sep-11-2018, 07:13 AM
Hi all ! This file works well, unless I try to exit. Look please at lines 17,18, 19. I am on Linux. Python 3.7.
import tty, sys, termios
class ReadChar():
def __enter__(self):
self.fd = sys.stdin.fileno()
self.old_settings = termios.tcgetattr(self.fd)
tty.setraw(sys.stdin.fileno())
return sys.stdin.read(1)
def __exit__(self, type, value, traceback):
termios.tcsetattr(self.fd, termios.TCSADRAIN, self.old_settings)
def test():
while True:
with ReadChar() as rc:
char = rc
#if ord(char) == 3:
# sys.exit()
#elif ord(char) <= 32:
if ord(char) <= 32:
print("You entered character with ordinal {}."\
.format(ord(char)))
else:
print("You entered character '{}'."\
.format(char))
#if char in "^C^D":
# sys.exit()
if __name__ == "__main__":
test()If I uncomment lines 17, 18, I have the following error:Error:sylvain@sylvain-HP-Laptop-15-bw0xx:~$ python get2.py
File "get2.py", line 18
sys.exit()
^

(from interpreter
)