Python OptionParser module, pythonoptionparser
OptionParser is a module used in python to process command lines. It is a necessary tool for process-based development using python.
Optparse, Which is powerful and easy to use, allows you to easily generate standard, Unix/Posix-compliant command line instructions
Case code
From optparse import OptionParserparse = OptionParser () parse. add_option ("-l", "-- language", action = "store_true", dest = "lan", default = True, help = "write language for Program") (option, arges) = parse. parse_args () if option. lan = True: print 'lan is true'
As shown above, first import the OptionParser class to create the OptionParser object
Use add_option () to define the command line parameters, and finally use parse_args () to parse the command line
Add_option Parameter Parsing. action contains store (default), store_false, store_false, store_const, append, count, and callback.
Another function of OptParser is to automatically generate program help information. For more information, see the previous study.