繁体   English   中英

docopt 不应用默认值

[英]docopt doesn't apply default value

我有以下使用字符串:

    usage = """Usage: 
    counts_editing_precent_total_editing_to_csv.py out <output> files <pileupPercentFiles>... [--percentageField=<kn>] [--numReadsField=<kn>]
    counts_editing_precent_total_editing_to_csv.py -h | --help

Options:
     -h --help  show this screen.
     --percentageField=<kn>  the column of the percent field in the input file  [default: 7] .
     --numReadsField=<kn>  the column of the num of reads field in the input file  [default: 4] .

    """

然后我执行这段代码

    args = docopt(usage)
    print(args)

我运行以下命令:

python <filename>.py out a files a b c

output 是:

{'--help': False,
 '--numReadsField': None,
 '--percentageField': None,
 '-h': False,
 '<output>': 'a',
 '<pileupPercentFiles>': ['a', 'b', 'c'],
 'files': True,
 'out': True}

如您所见,未使用默认值。 我已经看到其他类似的问题,其中解决方案是“在命令和它的描述之间有两个空格”,我确保我有。 我真的无法区分我的示例与文档中出现的示例。

我运行它并且它有效。 回想一下,您应该将使用字符串放在文件顶部的from docopt import docopt之前。 这是一个重现它的脚本。

"""Usage:
    counts_editing_precent_total_editing_to_csv.py out <output> files <pileupPercentFiles>... [--percentageField=<kn>] [--numReadsField=<kn>]
    counts_editing_precent_total_editing_to_csv.py -h | --help

Options:
     -h --help  show this screen.
     --percentageField=<kn>  the column of the percent field in the input file  [default: 7] .
     --numReadsField=<kn>  the column of the num of reads field in the input file  [default: 4] .

"""
from docopt import docopt
ARGUMENTS = docopt(__doc__)
print(ARGUMENTS)    

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM