[問題] 有關argument

看板Python作者 (愛得華)時間4年前 (2021/05/07 10:21), 編輯推噓1(103)
留言4則, 2人參與, 4年前最新討論串1/1
請問一個問題, 為何這樣寫會出現錯誤呢 [程式碼片段] 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://www.ptt.cc/bbs/Python/M.1620354073.A.8C2.html

05/07 11:06, 4年前 , 1F
parser_e.add_argument 這邊用nargs = "+" 會變成
05/07 11:06, 1F

05/07 11:07, 4年前 , 2F
list也變成role其中一個argument,但choice卻沒包含到
05/07 11:07, 2F

05/07 11:47, 4年前 , 3F
我改成nargs=2, 出現以下錯誤
05/07 11:47, 3F

05/07 11:48, 4年前 , 4F
role: error: argument role: invalid choice: 'list'
05/07 11:48, 4F
文章代碼(AID): #1WbAGPZ2 (Python)
文章代碼(AID): #1WbAGPZ2 (Python)