Python subprocess.Popen 不接受文本参数 [英] Python subprocess.Popen doesn't take text argument

查看:135
本文介绍了Python subprocess.Popen 不接受文本参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 subprocess.Popen 的 Python 3 文档,类构造函数接受一个可选参数 text(它应该控制文件对象 stdin、stdout 和 stderr 是否以文本模式打开).

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).

但是,当我尝试在构建 Popen 对象时设置 text=true 时,出现错误

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'

当我查看源代码时(我使用的是 Python 3.6.4),构造函数不接受任何参数 text.这里发生了什么?为什么文档说构造函数采用可选参数 text 而不是在我拥有的 subprocess.py 版本中?

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?

推荐答案

我感觉 text 参数是在 3.7 中添加的,而不是 3.6.

I have the feeling the text parameter has been added in 3.7, not 3.6.

文档的相关部分:

在 3.7 版更改:添加了 text 参数,作为universal_newlines 的更易于理解的别名.添加了 capture_output 参数.

Changed in version 3.7: Added the text parameter, as a more understandable alias of universal_newlines. Added the capture_output parameter.

这篇关于Python subprocess.Popen 不接受文本参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆