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: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'args': 0.04; 'sys': 0.05; 'exception.': 0.07; 'subject:How': 0.09; 'subject:command': 0.09; 'dec': 0.15; 'argparse': 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; 'wed,': 0.16; 'wrote:': 0.17; 'examples': 0.18; 'import': 0.21; "i'd": 0.22; 'command': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'separate': 0.27; 'options': 0.27; 'print': 0.32; 'to:addr:python-list': 0.33; 'subject:?': 0.35; 'add': 0.36; 'received:org': 0.36; 'but': 0.36; 'wanted': 0.36; "didn't": 0.36; 'should': 0.36; 'charset:us-ascii': 0.36; 'quite': 0.37; 'subject:: ': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'where': 0.40; 'content-disposition:inline': 0.60 Date: Wed, 5 Dec 2012 18:42:37 +0100 From: Bruno Dupuis To: python-list@python.org Subject: Re: How does one make argparse print usage when no options are provided on the command line? References: <20121205084830.74e842119d151781db385406@lavabit.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20121205084830.74e842119d151781db385406@lavabit.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1354729351 news.xs4all.nl 6844 [2001:888:2000:d::a6]:36069 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:34299 On Wed, Dec 05, 2012 at 08:48:30AM -0800, rh 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. > this is quite raw, but i'd add import sys if len(sys.argv) == 1: sys.argv.append('-h') before I call parser.parse_args() Should work -- Bruno Dupuis