I'm using Pycharm on unix. I'm trying to read a single character (like 'y' or 'n') from the console. It runs fine, when I execute it on the command line, but when I'm running the program inside Pycharm I get the following error:
termios.error: (25, 'Inappropriate ioctl for device')
I know, that the ide is not a tty, but I haven't found a workaround.
This is my function (seems to be pretty standard) to read the character.
def getch():
import sys, tty, termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(fd)
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
while True:
char = getch()
if char == 'q':
exit()
else:
print char