classification
Title: The documentation for the print function should explain/point to how to control the sys.stdout encoding
Type: Stage:
Components: Documentation Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: merwok Nosy List: docs@python, merwok, r.david.murray, zachary r.
Priority: normal Keywords: patch

Created on 2011-08-24 13:18 by r.david.murray, last changed 2011-11-30 15:25 by merwok.

Files
File name Uploaded Description Edit
functions_print_doc.patch zachary r., 2011-08-25 03:13 Add documentation to the print function detailing where it gets it's encoding information from. review
functions_print_doc_2.patch zachary r., 2011-11-30 03:59 Revise patch based on code review review
print-encoding.diff merwok, 2011-11-30 15:25
Messages (7)
msg142880 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-08-24 13:18
A common problem encountered when using python3 is writing non-ascii to stdout.  This will work fine if stdout is a terminal and the terminal encoding handles the characters, but will fail if stdout is later redirected to a pipe.  The docs for sys.stdout and for print should contain or point to an explanation of why, and how to solve the problem (ie: how to set the encoding for sys.stdout/sys.stderr).

Note that IMO it makes more sense for sys.stdout to default to the LOCALE encoding, but that should be a separate issue.
msg142881 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-08-24 13:21
Victor says it defaults to LOCALE in 3.3.  The documentation should still be expanded to mention this even in 3.3, though.
msg142883 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-08-24 13:36
Ah, this was actually fixed in 3.2, so it is only 2.7 where there is the different (and long standing) problem of output of unicode to a pipe.

So, the doc issue boils down to mentioning how the encoding for stdout/stderr is derived (LOCALE, overridden by PYTHONIOENCODING if set, as far as I can tell).
msg142953 - (view) Author: Zachary Richey (zachary r.) Date: 2011-08-25 03:13
I'm not sure if this is good documentation, but it explains how the encoding is gotten for stdout and stderr.
msg148497 - (view) Author: Éric Araujo (merwok) * (Python committer) Date: 2011-11-28 16:05
Thanks for the patch.  It was reviewed on our code review tool; if you did not get an email (there are glitches), follow the link on the right of your patch in the list of files.
msg148638 - (view) Author: Zachary Richey (zachary r.) Date: 2011-11-30 03:59
I've reworded the patch and fixed the issues in the patch pointed out by eric.araujo.
msg148663 - (view) Author: Éric Araujo (merwok) * (Python committer) Date: 2011-11-30 15:25
Thanks.  Here’s another take: I think the wording is better, but it’s longer.  I removed the reference to sys.stdin, which you don’t print to: I haven’t checked if the doc for the input function should talk about the encoding too.
History
Date User Action Args
2017-03-24 16:29:59serhiy.storchakalinkissue18713 superseder
2011-11-30 15:25:08merwoksetfiles: + print-encoding.diff
assignee: docs@python -> merwok
messages: + msg148663
2011-11-30 03:59:35zachary r.setfiles: + functions_print_doc_2.patch

messages: + msg148638
2011-11-28 16:05:03merwoksetnosy: + merwok
messages: + msg148497
2011-08-25 03:13:23zachary r.setfiles: + functions_print_doc.patch

nosy: + zachary r.
messages: + msg142953

keywords: + patch
2011-08-24 13:36:16r.david.murraysetmessages: + msg142883
2011-08-24 13:21:20r.david.murraysetmessages: + msg142881
2011-08-24 13:18:13r.david.murraycreate