0

I want to use the msvcrt.getch function as in the following example:

print 'Press s or n to continue:\n'
input_char = msvcrt.getch()
if input_char.upper() == 'S': 
   print 'YES'

But when I use it like this:

n = msvcrt.getch()
print(n)

The output is

b'\xff'

and it doesn't ask user for input.

Is this what is expected from msvcrt.getch() method? If not, how can I fix it?

Thanks!

1 Answers1

0

found the answer here: link

msvcrt returns a byte string and will require decoding using the below:

input_char = bytes.decode(msvcrt.getch(), encoding="utf-8")

or you can change the code to compare :b[input_char]

cd-6
  • 180
  • 13