【发布时间】:2018-11-29 10:26:02
【问题描述】:
Python docopt 在简单的情况下工作正常,但在这种情况下,它一直说-c requires argument,尽管它有一个参数。
最少的代码(Python 3.6):
'''Usage:
test_docopt.py x YYY ZZZ [-a AAA] [-b BBB] [-c CCC]
Options:
-a AAA description
-b BBB description
-c CCC description'''
from docopt import docopt
print(docopt(__doc__))
结果:
C:\>python3 test_docopt.py x foo bar -a alpha -b bravo -c charlie
-c requires argument
Usage:
test_docopt.py x YYY ZZZ [-a AAA] [-b BBB] [-c CCC]
C:\>
我做错了什么?
【问题讨论】:
-
我无法在 windows 或 linux 上重现
-
您能否确认 shell 中没有发生任何奇怪的事情,并且所有参数实际上都已传入。尝试将
import sys; print(sys.argv)放入脚本文件中。 -
@HåkenLid 谢谢;就是这样! (说来话长……但如果没有你的暗示,我不会把它弄糊涂的)。