Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #34310 > unrolled thread

Re: How does one make argparse print usage when no options are provided on the command line?

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2012-12-05 11:31 -0700
Last post2012-12-05 11:31 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: How does one make argparse print usage when no options are provided on the command line? Ian Kelly <ian.g.kelly@gmail.com> - 2012-12-05 11:31 -0700

#34310 — Re: How does one make argparse print usage when no options are provided on the command line?

FromIan Kelly <ian.g.kelly@gmail.com>
Date2012-12-05 11:31 -0700
SubjectRe: How does one make argparse print usage when no options are provided on the command line?
Message-ID<mailman.517.1354732351.29569.python-list@python.org>
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()

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web