Python argparse: Force a list item to be unique

后端 未结 4 1708
广开言路
广开言路 2021-01-19 16:17

Being able to validate the list items using choices=servers below is nice.

servers = [ \"ApaServer\", \"BananServer\", \"GulServer\", \"SolServ         


        
4条回答
  •  余生分开走
    2021-01-19 16:55

    I don't think, that you can enforce this with argparse, but I also don't see any reason to do so. Just document in help that duplicates are ignored. If the user passes duplicate arguments to --only, just let her do so, and ignore the duplicate argument when processing the option arguments (e.g. by turing the list into a set() before processing).

提交回复
热议问题