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

Fix output encoding mismatch #415

Merged
merged 1 commit into from
Apr 27, 2020
Merged

Fix output encoding mismatch #415

merged 1 commit into from
Apr 27, 2020

Conversation

mehrdadn
Copy link
Contributor

@mehrdadn mehrdadn commented Apr 27, 2020

Outputting Unicode on Windows can result in an error since the default encoding for open() (cp1252) can be different from that of stdio. [1] Here we make it match that of the underlying stream.

For earlier Python versions it would also be necessary to change the default encoding for stdio to utf-8, but I avoided doing that here since the default appears to have been already changed to UTF-8 as of Python 3.7(?).

[1] This can be observed by running this in the Command Prompt:

> python -c "import os, sys; print((sys.stdout.encoding, open(os.devnull, 'w').encoding))"
('utf-8', 'cp1252')

Copy link
Contributor

@kavigupta kavigupta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@kavigupta kavigupta merged commit a8ffb68 into master Apr 27, 2020
@kavigupta kavigupta deleted the windows-encoding branch April 27, 2020 00:21
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

Successfully merging this pull request may close these issues.

None yet

2 participants