4

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
jackson
  • 386
  • 1
  • 4
  • 21
  • Did you ever solve this? I am trying to help someone who is [getting the same error](http://stackoverflow.com/questions/32193435/user-input-with-a-timeout-in-a-loop) on OSX for getch(). – KobeJohn Sep 02 '15 at 07:07
  • 1
    No, I didn't find any solution. I just defined a force (s.th. like --f) command-line argument with argparse as a workaround, which works for most of my use cases. – jackson Sep 02 '15 at 08:00

0 Answers0