问题
According to the Python 3 documentation for subprocess.Popen, the class constructor takes an optional argument text
(which is supposed to control whether the file objects stdin, stdout and stderr are opened in text mode).
However, when I try setting text=true
upon construction of a Popen
object, I get the error
Failed: TypeError: __init__() got an unexpected keyword argument 'text'
and when I look in the source code (I'm using Python 3.6.4), the constructor takes no argument text
. What is going on here? Why does the documentation say the constructor takes an optional argument text
when it doesn't in the version of subprocess.py
that I have?
回答1:
I have the feeling the text parameter has been added in 3.7, not 3.6.
Relevant part of the doc:
Changed in version 3.7: Added the text parameter, as a more understandable alias of universal_newlines. Added the capture_output parameter.
来源:https://stackoverflow.com/questions/52663518/python-subprocess-popen-doesnt-take-text-argument