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


Groups > comp.lang.python > #5256

Re: Customize help output from optparse (or argparse)

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Content-Type text/plain; charset="UTF-8"
Message-Id <2635961.LZWGnKmheA@PointedEars.de>
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <usenet@PointedEars.de>
Organization PointedEars Software (PES)
Date Thu, 12 May 2011 22:22:20 +0200
User-Agent KNode/4.4.7
Content-Transfer-Encoding 8Bit
Subject Re: Customize help output from optparse (or argparse)
Newsgroups comp.lang.python
References <MPG.2836013fca77f958989809@news.individual.de>
Followup-To comp.lang.python
MIME-Version 1.0
Lines 57
NNTP-Posting-Date 12 May 2011 22:22:20 CEST
NNTP-Posting-Host 2ebdfbf8.newsspool2.arcor-online.net
X-Trace DXC=kiDkhBXe?51D]ncZ]`hZ;1A9EHlD;3Yc24Fo<]lROoR18kF<OcfhCO;6[\=IgUCmV6DZm8W4\YJN<T<8F<]0D<`9Ce:a8G7V1f5i\6]l@kbhR?
X-Complaints-To usenet-abuse@arcor.de
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:5256

Followups directed to: comp.lang.python

Show key headers only | View raw


Thorsten Kampe wrote:

> I'm using optparse for a little Python script.
> 
> 1. The output from "--help" is:
> """
> Usage: script.py <arg>
> 
> script.py does something
> 
> Options:
>   -h, --help   show this help message and exit
> """
> 
> I would prefer to have the description before the usage, like...
> """
> script.py does something
> 
> Usage: script.py <arg>
> 
> Options:
>   -h, --help   show this help message and exit
> """
> 
> 2. The output from "--doesnotexit" is:
> """
> Usage: script.py <arg>
> 
> script.py: error: no such option: --doesnotexist
> """
> 
> I would prefer to have the error first, then the usage and additionally
> the options, like...
> """
> script.py: error: no such option: --doesnotexist
> 
> Usage: script.py <arg>
> 
> Options:
>   -h, --help   show this help message and exit
> """
> 
> Is that possible with either optparse or the "new kid on the block"
> argparse. If so how?

You can easily have #1 with optparse.OptionParser(usage="…")¹, but optparse 
is deprecated in favor of argparse.ArgumentParser.  I do not think you can 
have #2 with either optparse or argparse: OptionParser() would print the 
error message last, and ArgumentParser() would not print the description
on error.  Subclassing ArgumentParser might be feasible, though.

______
¹  <http://PointedEars.de/devel/tools/text/odfinfo/>
-- 
PointedEars

Bitte keine Kopien per E-Mail. / Please do not Cc: me.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Customize help output from optparse (or argparse) Thorsten Kampe <thorsten@thorstenkampe.de> - 2011-05-12 15:38 +0200
  Re: Customize help output from optparse (or argparse) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-05-12 22:22 +0200
    Re: Customize help output from optparse (or argparse) Karim <karim.liateni@free.fr> - 2011-05-12 22:40 +0200
    Re: Customize help output from optparse (or argparse) Thorsten Kampe <thorsten@thorstenkampe.de> - 2011-05-21 23:53 +0200

csiph-web