Optparse built-in modules are used to process Python command line parameters.
Simple Process
First, you must import the Optionparser class to create a Optionparser object:
- from  OPTPARSE  import  OPTIONPARSER  
- [...]
- Parser = Optionparser ()
Then, use add_option to define the command-line arguments:
- Parser.add_option (Opt_str, ...,
- Attr=value, ...)
Each command-line argument consists of the parameter name string and the parameter property. such as- f or –file are the long and short parameter names:
- parser.add_option ("-F", "--file", ...)
Finally, once you have defined all the command-line arguments, call Parse_args () to resolve the program's command line:
- (options, args) = Parser.parse_args ()
Example
Here is a simple example of using Optparse:
- from Optparse Import Optionparser
- [...]
- Parser = Optionparser ()
- parser.add_option ( "-F" ,  "--file" , dest= "filename" ,  
- help= "Write report to file" , metavar= "FILE"
- parser.add_option ( "-Q" ,  "--quiet" ,  
- action= "Store_false" , dest= "verbose" , default= true ,  
- help= "Don ' T print status messages to stdout"
- (options, args) = Parser.parse_args ()
Python Module Learning--optparse