python - 使用子进程时出现类型错误
问题描述
我正在使用子进程将另一个 python 文件的输出捕获到当前文件中。这是我的代码-
import subprocess
a= subprocess.run('python3 try1.py', capture_output=True,shell=True)
但是当我运行代码时,我得到一个错误 -
<pre>Traceback (most recent call last):
File "test2.py", line 4, in <module>
c1= subprocess.run('python3 test2.py', capture_output=True,shell=True)
File "/usr/lib/python3.6/subprocess.py", line 423, in run
with Popen(*popenargs, **kwargs) as process:
TypeError: __init__() got an unexpected keyword argument 'capture_output'
</pre>
我正在运行 Python 3.6.8。此外,我的 PC 上不存在名为 subprocess.py 的文件。以前有,不过我删了 感谢大家的帮助!
解决方案
该capture_output
参数在您正在使用的 Python 3.6 中不存在。因此错误。您可以改用它:
subprocess.check_output(['python3', 'try1.py'])
推荐阅读
- html - 为什么不显示图案
- javascript - 使用 location.href 时页面挂起
- python - 应该返回浮点数但它返回“ - ”我该如何解决这个问题?
- data-analysis - AttributeError:模块“pyDEA”没有属性“DEAProblem”
- angular - 使用 GoTo 方法的相对导航
- android - 如何更改启动器中状态栏的颜色?
- google-compute-engine - 如何保持 NodeJS 云计算 VM 在线?
- c# - 启用辅助功能时,Xamarin iOS UIView 拖动不起作用
- r - R flexdashboard垂直滚动切断图形
- azure - 是否可以对已等待补液的 Azure blob 补液?