我test.py
使用 python 子进程运行 python 脚本。我想发送两个字符串'John', 'Henry'
作为参数并从 test.py 中读取参数值。我想要这样的东西
subprocess.call(['python3', 'test.py']) #add two names 'John', 'Henry' as argument
测试文件
print(name1) #print John
print(name2) #print Henry
我怎样才能做到这一点?
试试这个:
subprocess.call(['python3', 'test.py', 'John', 'Henry'])
并将 test.py 更改为如下所示:
import sys
print(sys.argv[1])
print(sys.argv[2])
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句