小编Kil*_*was的帖子

如何在pyinvoke中使用可变数量的参数

我想在pyinvoke的任务中使用可变数量的参数.像这样:

from invoke import task

@task(help={'out_file:': 'Name of the output file.', 
            'in_files': 'List of the input files.'})
def pdf_combine(out_file, *in_files):
    print( "out = %s" % out_file)
    print( "in = %s" % list(in_files))
Run Code Online (Sandbox Code Playgroud)

以上只是我尝试过的众多变化中的一种,但似乎pyinvoke无法处理可变数量的参数.这是真的?

上面的代码导致了

$ invoke pdf_combine -o binder.pdf -i test.pdf test1.pdf
No idea what '-i' is!
Run Code Online (Sandbox Code Playgroud)

类似的,如果我定义pdf_combine(out_file,in_file),在in_file之前没有星号

$ invoke pdf_combine -o binder.pdf -i test.pdf test1.pdf
No idea what 'test1.pdf' is!
Run Code Online (Sandbox Code Playgroud)

如果我只使用下面的一个in_file调用任务,则运行OK.

$ invoke pdf_combine -o binder.pdf -i test.pdf
out = binder.pdf
in = ['t', 'e', 's', 't', '.', 'p', …
Run Code Online (Sandbox Code Playgroud)

python pyinvoke

6
推荐指数
1
解决办法
404
查看次数

标签 统计

pyinvoke ×1

python ×1