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


Groups > comp.lang.python > #34325

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

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'args': 0.04; 'exception.': 0.07; 'subject:How': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:command': 0.09; '2.7': 0.13; 'dec': 0.15; '3.3.': 0.16; 'argparse': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'statement.': 0.16; 'subject: \n ': 0.16; 'subject:argparse': 0.16; 'subject:options': 0.16; 'subject:usage': 0.16; 'subject:when': 0.16; 'sys.exit(1)': 0.16; 'wed,': 0.16; 'wrote:': 0.17; 'examples': 0.18; 'thanks.': 0.21; 'command': 0.24; 'header :User-Agent:1': 0.26; 'am,': 0.27; 'separate': 0.27; 'options': 0.27; 'header:X-Complaints-To:1': 0.28; 'print': 0.32; 'to:addr :python-list': 0.33; 'subject:?': 0.35; 'received:org': 0.36; 'but': 0.36; 'wanted': 0.36; "didn't": 0.36; 'charset:us-ascii': 0.36; 'skip:p 20': 0.36; 'subject:: ': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'received:sd.cox.net': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
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 Wed, 5 Dec 2012 12:52:12 -0800
References <20121205084830.74e842119d151781db385406@lavabit.com> <CALwzidmAOaVUpOM4EJp-FGGAi4f0nT-tsU8_JP-g1qG-GY+N5g@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host ip184-187-163-27.sb.sd.cox.net
User-Agent dsodnetnin
X-Mailer EZnn0.37p
X-Newsreader EZnn0.37p
X-Gmane-NNTP-Posting-Host EZnn0.37p
Original-Received from slem by 1.1 with local
X-No-Archive yes
Archive no
X-Archive expiry=11
X-Archive encrypt
X-Operating-System Barebones_6.1
X-Gmane-NNTP-Posting-Host 192.168.1.1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.525.1354740745.29569.python-list@python.org> (permalink)
Lines 21
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1354740745 news.xs4all.nl 6957 [2001:888:2000:d::a6]:56922
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:34325

Show key headers only | View raw


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


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