Q's on my first python script
Marius Gedminas
mgedmin at gmail.com
Thu May 14 18:15:23 EDT 2009
On May 11, 12:30 pm, Nick Craig-Wood <n... at craig-wood.com> wrote:
> def __init__(self):
> usage = '''Usage: %prog [options] YYMMDD
> %prog -h|--help
> '''
> parser = OptionParser(usage=usage)
> parser.add_option("-n", "--no-newline", dest="nonl",
> action="store_true", help="omit newline in output")
> (options, args) = parser.parse_args();
> try:
> weekday = self.wkday_abbrev(args[0])
> except BadDateString, e:
> print usage
> print e
> sys.exit(1)
I would recommend printing error messages to sys.stderr.
BTW, in this particular case you may want to use
parser.error(e)
instead of print + sys.exit.
--
Marius Gedminas
More information about the Python-list
mailing list