Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将未知长度的选项传递给子流程_Python_Subprocess_Python 2.x - Fatal编程技术网

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)