我正在使用子过程将另一个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。 另外,我的电脑上没有名为subprocess.py的文件。它曾经,但是我删除了它。 感谢所有帮助!
答案 0 :(得分:3)
您正在使用的Python 3.6中不存在capture_output
参数。因此,错误。您可以改用它:
subprocess.check_output(['python3', 'try1.py'])