On Fri, Nov 20, 2009 at 5:03 AM, Kent Johnson <[email protected]> wrote:

> On Thu, Nov 19, 2009 at 5:47 PM, Geoff Dutton <[email protected]>
> wrote:
> > Do you have recommendations for handling missing positional arguments?
> I'm
> > a huge fan of OptionParser module and use it in several programs to
> handle
> > options, but there must be an eligant way of handling missing arguments
> and
> > alerting the user.  Here is how I have done it ...
> >
> > import sys
> > from subprocess import call
> > from optparse import OptionParser
> >
> > if __name__=='__main__':
> >
> >     opt = OptionParser(
> >         usage = "usage: %prog [options] site year",
> >         description = "Count number of ITX files from a station for a
> given
> > year."
> >     )
> >     opt.add_option("-e", action="store",
> >             dest="email_add", help="send table as email")
> >     opt.add_option("-l", '--lenght', action="store", default="30",
> >             dest="len", help="Number of lines in table.")
> >
> >     (options, args) = opt.parse_args()
> >
> >     if len(args) != 2:
> >         call(["countinj.py", "-h"])
> >         sys.exit()
>
> opt.print_help() seems to be what you want here.
>
> Kent
>
>
Exactly!  Thank you.
Geoff
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to