Posted By

manatlan on 10/30/09


Tagged

python tech


Versions (?)

python command line with optparse


 / Published in: Python
 

  1. from optparse import OptionParser
  2.  
  3. USAGE = """usage: %prog [options] <file1> <file2> ... """
  4.  
  5. if __name__ == "__main__":
  6. parser = OptionParser(usage=USAGE)
  7. parser.add_option("-o", "--output", dest="filename",
  8. help="generate output infile", metavar="FILE")
  9. parser.add_option("-q", "--quiet",
  10. action="store_false", dest="verbose", default=True,
  11. help="don't print status messages to stdout")
  12.  
  13. (options, args) = parser.parse_args()
  14. if not args:
  15. parser.print_help()
  16. else:
  17. print options.verbose
  18. print options.filename
  19. print args

Report this snippet  

You need to login to post a comment.