我很困惑。所以我想用我的程序program10.py
它使用其他程序,例如other_program
Python子进程命令行错误
所以我可能会像这样运行:
python3 program10.py other_program
的other_program
接受一个int参数 这里是我的program10.py
代码:
import time
import subprocess
n = 2**10
myList = []
while n <= 2**15:
before = time.process_time()
subprocess.call(n)
after = time.process_time()
print(n, after-before)
myList.append(after-before)
n *= 2
print(myList)
当然,我得到这个大错误:
Traceback (most recent call last):
File "program10.py", line 7, in <module>
subprocess.call(n)
File "/usr/lib/python3.5/subprocess.py", line 557, in call
with Popen(*popenargs, **kwargs) as p:
File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.5/subprocess.py", line 1440, in _execute_child
args = list(args)
TypeError: 'int' object is not iterable
我毫不怀疑我使用subprocess.call是完全错误的,因为我不明白这一点,也没有其他SO问题或Python文档帮助我解决问题。如果任何人都可以告诉我它与我的程序有什么关系,那意味着很多。
第一次通过循环,尝试执行'subprocess.call(2 ** 10)' 。第二次是'subprocess.call(2 ** 11)'。 Python期望的是要执行的程序的*名称*也许是'sys.argv [1]'传递给你的程序的命令行参数... – jasonharper