/ Published in: Python
Parsing arguments in Python
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
logging.basicConfig() parser = OptionParser(usage="%prog [-f] [-q] <free-form date string>", version=str(__version__)) parser.add_option("-f", "--force-update", action='store_true', dest="force_update", default=False, help="force self-updating of TRANSLATION_DICT in this file", metavar="FILE") parser.add_option("-q", "--quiet", action="store_false", dest="verbose", default=True, help="don't print debug messages to stdout") (options, args) = parser.parse_args() if len(args) != 1: parser.error("you have missed query string") date_string = args[0] if options.verbose: print '%s -> %s' % (date_string, parse(date_string, loglevel=logging.DEBUG, force_update=options.force_update)) else: print parse(date_string, loglevel=logging.WARNING, force_update=options.force_update)