Python 将未知长度的选项传递给子流程
这是我现有的(非功能性)代码Python 将未知长度的选项传递给子流程,python,subprocess,python-2.x,Python,Subprocess,Python 2.x,这是我现有的(非功能性)代码 鉴于“options”的长度不总是固定的,如何正确传递其内容?这是最简单的示例,但实际上我有类似的代码调用几个不同的命令。将命令作为平面列表或元组传递: def call_GM(sourcefile): source = os.path.splitext(sourcefile) outfile = '"' + source[0] + '_straightened' + source[1] + '"' options = ['convert',
鉴于“options”的长度不总是固定的,如何正确传递其内容?这是最简单的示例,但实际上我有类似的代码调用几个不同的命令。将命令作为平面列表或元组传递:
def call_GM(sourcefile):
source = os.path.splitext(sourcefile)
outfile = '"' + source[0] + '_straightened' + source[1] + '"'
options = ['convert', '-auto-orient', sourcefile, outfile]
command = 'gm'
subprocess.call([command] + options)
注意:将选项
修改为列表,因为不允许列表+元组
def call_GM(sourcefile):
source = os.path.splitext(sourcefile)
outfile = '"' + source[0] + '_straightened' + source[1] + '"'
options = ['convert', '-auto-orient', sourcefile, outfile]
command = 'gm'
subprocess.call([command] + options)