Installation:
1. Direct installation on the line WINDOW10 the Python 2.7 feels no problem.
Document:
Official documents:
Https://docs.python.org/2/library/optparse.html
Use:
#coding: Utf-8 import optparse def main (): Usage = "Usage:%prog [options] arg" parser = Optparse.
Optionparser (usage) parser.add_option ("F", dest= "filename", help= "read data from filename") Parser.add_option ("-V", "--verbose", action= "Store_true", dest= "verbose") Parser.add_opti On ("Q", "--quiet", action= "Store_false", dest= "verbose") (options, args) = Parser.parse_
Args () print Parser.parse_args () print options.filename print args args.append (options.filename) Print args if __name__ = = "__main__": Main () "" "F5 <values at 0x3360c88: {' verbose ': None, ' filename ' : None}>, []) None [] [None] CMD c:\users\dell>python C:\Users\dell\Desktop\TEMP\AS.py-h Usage:AS.py [options]
Arg Options:-H,--help show this help and exit-f FILENAME read data from Filename-v,--verbose -Q,--quiet C:\USERS\DELL>PYTHon C:\Users\dell\Desktop\TEMP\AS.py-f 1 2 3 (<values at 0x2b52ac8: {' verbose ': None, ' filename ': ' 1 '}>, [' 2 ', ' 3 '] ) 1 [' 2 ', ' 3 '] [' 2 ', ' 3 ', ' 1 '] ' "
Reproduced:
http://shelly-kuang.iteye.com/blog/797713