python command line with optparse


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.