argparse — requiring either 2 values or none for an optional argument

后端 未结 4 1095
你的背包
你的背包 2021-02-06 01:07

I\'m trying to make an optional argument for a script that can either take no values or 2 values, nothing else. Can you accomplish this using argparse?

# desired         


        
4条回答
  •  星月不相逢
    2021-02-06 01:45

    How about the required argument:parser.add_argument("-a", "--action", nargs=2, action="store", help="do some action", required=False)

提交回复
热议问题