相关疑难解决方法(0)

禁用argparse和optparse的唯一前缀匹配

当我使用Python的argparse或optparse命令行参数解析器时,参数的任何唯一前缀都被认为是有效的,例如

$ ./buildall.py --help
usage: buildall.py [-h] [-f]

Build all repositories

optional arguments:
  -h, --help   show this help message and exit
  -f, --force  Build dirty repositories
Run Code Online (Sandbox Code Playgroud)

作品有--help,--hel,--he的帮助选项,以及--forc--fo为强制选项.

可以以某种方式关闭此行为吗?我想获得不完整参数的错误消息.

python optparse argparse

12
推荐指数
2
解决办法
1604
查看次数

标签 统计

argparse ×1

optparse ×1

python ×1