点击不会让我传递多个文件,尽管应该可以 [英] Click wouldn't let me pass multiple files, although it should be possible

查看:54
本文介绍了点击不会让我传递多个文件,尽管应该可以的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将click用于多个文件.例如:

I'm trying to use click for multiple files. For example:

@cli.command("test")
@click.argument('input', type=click.File('rb'))
def test(input):
    with click.progressbar(input, label='READING') as bar:
        for x in bar:
            pass

当我做这样的事情时:

script test ~/ololo/*

我得到:

Error: Got unexpected extra arguments ( ... listing all files in folder ...)

推荐答案

您需要使用nargs参数.如果将其设置为-1,则将接受无限数量的参数: http://click.pocoo.org/6/arguments/#variadic-arguments

You need to use nargs parameter. If it is set to -1, then an unlimited number of arguments is accepted: http://click.pocoo.org/6/arguments/#variadic-arguments

@cli.command("test")
@click.argument('input', nargs=-1, type=click.File('rb'))
def test(input):
    with click.progressbar(input, label='READING') as bar:
        for x in bar:
            pass

这篇关于点击不会让我传递多个文件,尽管应该可以的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆