[issue17286] Make subprocess handling text output with universal_newlines more obious
p = subprocess.Popen(args, universal_newlines=True) # Success! and at a small comment below the example to explain that flag
New submission from Baptiste Lepilleur: It tooks me a while to figure out that using universal_newlines was the solution to "tell" subprocess that I wanted text string output instead of byte string. A search on stackoverflow shows that this issue is common and the solution nearly unknown (answer is usually to decode the byte string manually)... Because dealing with text output is IMHO the most common use case, the subprocess documentation should make it easier to "find" the recipe. I would suggest changing the documentation so that the universal_newlines is made obvious as it is very important: 1) the first /bin/vikings example be modified to show the use of this flag (at the top of the documentation, most people copy/past that): 2) change other example similarly when that make sense, IMHO: - ifconfig example - one of the subprocess.check_output example - subprocess.check_output() example, consider separating the byte string / text string example for increased visibility 3) consider adding a section with an obvious title "Dealing with binary and text input/output", providing examples and pointer to the correct documentation (I would place it after the convenience functions section for visibility). I think this would help attracting "eye" on this large piece of documentation. ---------- assignee: docs@python components: Documentation messages: 182872 nosy: Baptiste.Lepilleur, docs@python priority: normal severity: normal status: open title: Make subprocess handling text output with universal_newlines more obious type: enhancement versions: Python 3.1, Python 3.2, Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17286> _______________________________________
Mark Lawrence added the comment: @Baptiste can you provide a patch for this? ---------- nosy: +BreamoreBoy _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17286> _______________________________________
Changes by Terry J. Reedy <tjreedy@udel.edu>: ---------- stage: -> needs patch versions: +Python 3.4, Python 3.5 -Python 3.1, Python 3.2, Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17286> _______________________________________
bbayles <bbayles@gmail.com> added the comment: This is fixed in 3.7 with the `text` parameter. See GitHub PR 4049: https://github.com/python/cpython/pull/4049 ---------- nosy: +bbayles _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue17286> _______________________________________
Change by Mark Lawrence <breamoreboy@gmail.com>: ---------- nosy: -BreamoreBoy _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue17286> _______________________________________
Change by Cheryl Sabella <cheryl.sabella@gmail.com>: ---------- resolution: -> duplicate stage: needs patch -> resolved status: open -> closed superseder: -> subprocess.run should alias universal_newlines to text _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue17286> _______________________________________
participants (5)
-
Baptiste Lepilleur
-
bbayles
-
Cheryl Sabella
-
Mark Lawrence
-
Terry J. Reedy