Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #34325
| From | rh <richard_hubbe11@lavabit.com> |
|---|---|
| Subject | Re: How does one make argparse print usage when no options are provided on the command line? |
| Date | 2012-12-05 12:52 -0800 |
| References | <20121205084830.74e842119d151781db385406@lavabit.com> <CALwzidmAOaVUpOM4EJp-FGGAi4f0nT-tsU8_JP-g1qG-GY+N5g@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.525.1354740745.29569.python-list@python.org> (permalink) |
On Wed, 5 Dec 2012 11:31:57 -0700 Ian Kelly <ian.g.kelly@gmail.com> wrote: > On Wed, Dec 5, 2012 at 9:48 AM, rh <richard_hubbe11@lavabit.com> > wrote: > > I have argparse working with one exception. I wanted the program to > > print out usage when no command line options are given. But I only > > came across other examples where people didn't use argparse but > > instead printed out a separate usage statement. So they used > > argparse for everything but the case where no command line args are > > given. > > if len(sys.argv) <= 1: > parser.print_usage() > sys.exit(1) > else: > args = parser.parse_args() Thanks. It works in 2.7 and 3.3.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: How does one make argparse print usage when no options are provided on the command line? rh <richard_hubbe11@lavabit.com> - 2012-12-05 12:52 -0800
csiph-web