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

should document how to deal with stdin/stdout and unicode #241

Open
anarcat opened this issue Sep 18, 2016 · 0 comments
Open

should document how to deal with stdin/stdout and unicode #241

anarcat opened this issue Sep 18, 2016 · 0 comments

Comments

@anarcat
Copy link

anarcat commented Sep 18, 2016

i found the file i/o section to be refreshing and enlightening, but it works only on files we open, which unfortunately doesn't work with stdin/stdout and friends.

there are various idioms out there to fix this. here i have seen:

input_stream = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')

and here i have seen:

sys.stdout = codecs.getwriter('utf8')(sys.stdout)

both seem pretty ugly to me - is there a better way to do this in both py2 and py3 that we should document here?

my favorite right now is PYTHONIOENCODING=utf-8 but then that can't be done from within the program itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants