Website hosting service by Active-Venture.com
  

 Back to Index


6.20.2.7 Putting it all together

Here's what optparse-based scripts typically look like:

 

from optparse import OptionParser
[...]
def main():
    usage = "usage: \%prog [-f] [-v] [-q] firstarg secondarg"
    parser = OptionParser(usage)
    parser.add_option("-f", "--file", type="string", dest="filename",
                      help="read data from FILENAME")
    parser.add_option("-v", "--verbose",
                      action="store_true", dest="verbose")
    parser.add_option("-q", "--quiet",
                      action="store_false", dest="verbose")

    (options, args) = parser.parse_args()
    if len(args) != 1:
        parser.error("incorrect number of arguments")

    if options.verbose:
        print "reading \%s..." \% options.filename
    [... go to work ...]

if __name__ == "__main__":
    main()
 

  

 

© 2002-2004 Active-Venture.com Webhosting Service

 

Disclaimer: This documentation is provided only for the benefits of our hosting customers.
For authoritative source of the documentation, please refer to http://python.org/doc/

 

Active-Domain.com offers domain name registration, domain name transfer and domain search services  

Cheap domain registration : Register domain name or buy domain name, including free domain hosting services

 
 

Domain registration : Buy domain name or register domain name from $5.95/year only