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
2
  • Did you ever solve this? I am trying to help someone who is getting the same error on OSX for getch(). Commented Sep 2, 2015 at 7: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. Commented Sep 2, 2015 at 8:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.