Skip to content

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

@malversan

Description

@malversan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions