我想从另一个python脚本运行一个python脚本,但由于传递的参数中有一个空格而被阻塞。我试图运行从名为命令终端运行的脚本和论据,这样运行一个包含另一个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")
,但我得到无效的语法
你需要躲避空间:'使用os.system( 'python Duplicate_Checki.py“Google \ Control \ Center 7.5 \ Hardening'')' – inspectorG4dget
看看'subprocess.run'。它不会在空间上分裂。 – Artyer