You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Under Windows the msvcrt.getch() call returns bytes, not chars. In Python 3 both types are not compatible, so concatenating the result to a string fails with a TypeError.
This code in Platform.getkey() throws TypeError exception ALWAYS in Windows:
buffer = ''
for c in self.getchars(blocking):
buffer += c
...
I have ammended it to work by allowing the platform classes to return bytes instead of chars:
buffer = ''
for c in self.getchars(blocking):
try:
buffer += c
except TypeError:
buffer += ''.join([chr(b) for b in c])
...
This supports any platform that captures chars, multichars, bytes or multibytes. And also complies with the Python philosophy of trying instead of checking.
Tested in:
Windows 8.1
Python 3.6.1
The text was updated successfully, but these errors were encountered:
malversan
changed the title
Does not work on Windows
Does not work on Windows: TypeError
Mar 11, 2020
malversan
changed the title
Does not work on Windows: TypeError
Does not work on Windows with Python 3: TypeError
Mar 11, 2020
Under Windows the msvcrt.getch() call returns bytes, not chars. In Python 3 both types are not compatible, so concatenating the result to a string fails with a TypeError.
This code in Platform.getkey() throws TypeError exception ALWAYS in Windows:
I have ammended it to work by allowing the platform classes to return bytes instead of chars:
This supports any platform that captures chars, multichars, bytes or multibytes. And also complies with the Python philosophy of trying instead of checking.
Tested in:
Windows 8.1
Python 3.6.1
The text was updated successfully, but these errors were encountered: