Vishruth_kumar
Posts: 51
Joined: Thu Feb 04, 2016 6:07 pm
Location: Anand, Gujarat, India
Contact: Website Twitter YouTube

getch() module error

Mon Jun 13, 2016 7:05 pm

I am trying to use my keyboard to control motors using L298N Dual Hbridge PWM. I have written the code for taking input from keyboard as:
def getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch

This is just a portion of my code .After running the module I get error as:
char = getch()
fd = sys.stdin.fileno()
UnsuppoertedOperation : fileno()

Please help me out . Is there any need for me to download some module to support getch() ?

User avatar
Paeryn
Posts: 2986
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: getch() module error

Mon Jun 13, 2016 8:53 pm

At a guess, are you running it from within IDLE? If so sys is slightly different. sys.stdin, sys.stdout and sys.stderr aren't normal file streams when run from within IDLE and don't have file descriptors (they are pseudofiles).
She who travels light — forgot something.

Return to “Python”