Python: How to make an option to be required in optparse?

前端 未结 9 2119
走了就别回头了
走了就别回头了 2021-02-05 00:57

I\'ve read this http://docs.python.org/release/2.6.2/library/optparse.html

But I\'m not so clear how to make an option to be required in optparse?

I\'ve tried to

9条回答
  •  青春惊慌失措
    2021-02-05 01:12

    I would use argparse library that has this functionality embedded:

    PARSER.add_argument("-n", "--namespace", dest="namespace", required=True,
                  help="The path within the repo to the data base")
    

    argparse reference

提交回复
热议问题