[issue12832] The documentation for the print function should explain/point to how to control the sys.stdout encoding
New submission from R. David Murray <rdmurray@bitdance.com>: 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. ---------- assignee: docs@python components: Documentation messages: 142880 nosy: docs@python, r.david.murray priority: normal severity: normal status: open title: The documentation for the print function should explain/point to how to control the sys.stdout encoding versions: Python 2.7, Python 3.2, Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue12832> _______________________________________
R. David Murray <rdmurray@bitdance.com> added the comment: Victor says it defaults to LOCALE in 3.3. The documentation should still be expanded to mention this even in 3.3, though. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue12832> _______________________________________
R. David Murray <rdmurray@bitdance.com> added the comment: 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). ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue12832> _______________________________________
Zachary Richey <mach1723@gmail.com> added the comment: I'm not sure if this is good documentation, but it explains how the encoding is gotten for stdout and stderr. ---------- keywords: +patch nosy: +mach1723 Added file: http://bugs.python.org/file23042/functions_print_doc.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue12832> _______________________________________
Éric Araujo <merwok@netwok.org> added the comment: 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. ---------- nosy: +eric.araujo _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue12832> _______________________________________
Zachary Richey <mach1723@gmail.com> added the comment: I've reworded the patch and fixed the issues in the patch pointed out by eric.araujo. ---------- Added file: http://bugs.python.org/file23815/functions_print_doc_2.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue12832> _______________________________________
Éric Araujo <merwok@netwok.org> added the comment: 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. ---------- assignee: docs@python -> eric.araujo Added file: http://bugs.python.org/file23818/print-encoding.diff _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue12832> _______________________________________
Change by Irit Katriel <iritkatriel@yahoo.com>: ---------- type: -> enhancement versions: +Python 3.10, Python 3.9 -Python 2.7, Python 3.2, Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue12832> _______________________________________
participants (4)
-
Irit Katriel
-
R. David Murray
-
Zachary Richey
-
Éric Araujo