这是我现有的(非功能性)代码。
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])
如何正确传递"选项"的内容?鉴于它的长度并不总是固定的?这是最简单的例子,但我实际上有类似的代码调用几个不同的命令。
答案 0 :(得分:1)
将命令作为平面列表或元组传递:
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)
注意:将options
修改为列表,因为不允许list + tuple
。