This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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

Created on 2011-08-24 13:18 by r.david.murray, last changed 2022-04-11 14:57 by admin.

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 eric.araujo, 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 (eric.araujo) * (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 (eric.araujo) * (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
2022-04-11 14:57:21adminsetgithub: 57041
2020-10-25 22:58:27iritkatrielsettype: enhancement
versions: + Python 3.9, Python 3.10, - Python 2.7, Python 3.2, Python 3.3
2017-03-24 16:29:59serhiy.storchakalinkissue18713 superseder
2011-11-30 15:25:08eric.araujosetfiles: + print-encoding.diff
assignee: docs@python -> eric.araujo
messages: + msg148663
2011-11-30 03:59:35zachary r.setfiles: + functions_print_doc_2.patch

messages: + msg148638
2011-11-28 16:05:03eric.araujosetnosy: + eric.araujo
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