作者freeedward (爱得华)
看板Python
标题[问题] 有关argument
时间Fri May 7 10:21:04 2021
请问一个问题, 为何这样写会出现错误呢
[程式码片段]
parser_e = subparsers.add_parser('role', help='map', description='role arguments')
parser_e.add_argument("role", nargs='+', choices=['map'],
help='role command, available parameter is map')
subsubparsers = parser_e.add_subparsers()
parser_ee = subsubparsers.add_parser('map', help='create | list', description='role map arguments')
parser_ee.add_argument("map", nargs='+', choices=['create','list'],
help='map command, available parameter is create, list')
[执行命令]
tool role map list
[错误返回]
role: error: invalid choice: 'list' (choose from 'map')
--
~meow
★ Butter Yuki Cat ★ meow~
△ △
★ ╭ ╦╗ ═ ╭╬╗ ═╦═ ╦ ╬═╬ ╠╣ ╬═╬ ★ ▲ ▲
=▏ ̄▕=
★ ╬╬║║ ║║║ ║ ║ ╠═╣ ╠╬╗╭╦╗ ★ =███=
\_/
★ ║║║╩╗ ═ ╠╬╣ ═╬═ ╬ ╠═╣ ╭═╣╠╬╣ ★ ◥█◤
ζ∕ ﹨
★ ╚╬║ ║ ║║║║ ║╮ ║ ╩═╩ ╭═╣║║║ ★ ▌█▋▋
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 203.193.22.45 (香港)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1620354073.A.8C2.html
1F:推 lycantrope: parser_e.add_argument 这边用nargs = "+" 会变成 05/07 11:06
2F:→ lycantrope: list也变成role其中一个argument,但choice却没包含到 05/07 11:07
3F:→ freeedward: 我改成nargs=2, 出现以下错误 05/07 11:47
4F:→ freeedward: role: error: argument role: invalid choice: 'list' 05/07 11:48