Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work on Windows with Python 3: TypeError #10

Open
malversan opened this issue Mar 10, 2020 · 0 comments
Open

Does not work on Windows with Python 3: TypeError #10

malversan opened this issue Mar 10, 2020 · 0 comments

Comments

@malversan
Copy link

malversan commented Mar 10, 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:

        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

@malversan malversan changed the title Does not work on Windows Does not work on Windows: TypeError Mar 11, 2020
@malversan malversan changed the title Does not work on Windows: TypeError Does not work on Windows with Python 3: TypeError Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant