argparse module How to add option without any argument?

后端 未结 2 1275
天涯浪人
天涯浪人 2021-01-29 22:57

I have created a script using argparse.

The script needs to take a configuration file name as an option, and user can specify whether they need to proceed t

2条回答
  •  情书的邮戳
    2021-01-29 23:39

    To create an option that needs no value, set the action [docs] of it to 'store_const', 'store_true' or 'store_false'.

    Example:

    parser.add_argument('-s', '--simulate', action='store_true')
    

提交回复
热议问题