Parsing arguments in Python


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

Parsing arguments in Python


Copy this code and paste it in your HTML
  1. logging.basicConfig()
  2. parser = OptionParser(usage="%prog [-f] [-q] <free-form date string>", version=str(__version__))
  3. parser.add_option("-f", "--force-update",
  4. action='store_true', dest="force_update", default=False,
  5. help="force self-updating of TRANSLATION_DICT in this file", metavar="FILE")
  6. parser.add_option("-q", "--quiet",
  7. action="store_false", dest="verbose", default=True,
  8. help="don't print debug messages to stdout")
  9. (options, args) = parser.parse_args()
  10. if len(args) != 1:
  11. parser.error("you have missed query string")
  12. date_string = args[0]
  13. if options.verbose:
  14. print '%s -> %s' % (date_string, parse(date_string, loglevel=logging.DEBUG, force_update=options.force_update))
  15. else:
  16. print parse(date_string, loglevel=logging.WARNING, force_update=options.force_update)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.