OptionParser is a module used to process the command line in python. It is a necessary tool in our process development using python
Optparse. It is powerful and easy to use. It can Conveniently generate standard command line instructions that comply with Unix/Posix specifications
Example code
from optparse import OptionParser parse = 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 and create the OptionParser object
Use add_option () to define command line parameters, and finally use parse_args() to parse the command line
add_option parameter parsing, action includes store (default), store_false, store_false, store_const, append, count, callback
Another function of OptParser is to automatically generate help information for the program, which will be explained later. The above is a preliminary learning
The above is the detailed content of Detailed explanation of how to use the python OptionParser module. For more information, please follow other related articles on the PHP Chinese website!