我试图从另一个python脚本中运行python脚本,但是由于传递的参数中有一个空格,所以我被阻塞了。我试图运行的脚本是从命令终端运行的,其中包含名称和参数。
>>>Duplicate_Checki.py "Google Control Center" "7.5 Hardening"在我试图调用的第一个脚本中,代码如下所示:
def run_duplicate_check(self):
os.system("python Duplicate_Checki.py Google Control Center 7.5 Hardening") 我得到以下错误
Duplicate_Checki.py: error: unrecognized arguments: Center 7.5 Hardening也用同样的错误尝试了os.system("python Duplicate_Checki.py {} {}".format("Google Control Center" ,"7.5 Hardening"))
我也试过
os.system(python Duplicate_Checki.py "Google Control Center" "7.5 Hardening")但是我发现语法无效
发布于 2017-06-20 21:29:26
script.py
import sys
if __name__ == '__main__':
args = sys.argv[1:]
print(args[0])
print(args[1])runner.py
from subprocess import call
call(["python3", "script.py", "Google Control Center", "7.5 Hardening"])执行python3 runner.py,输出:
Google Control Center
7.5 Hardening请参阅https://docs.python.org/3/library/subprocess.html
#subprocess.run,#subprocess.check_output,#subprocess.call
https://stackoverflow.com/questions/44663213
复制相似问题