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


Groups > comp.lang.python > #5236

Customize help output from optparse (or argparse)

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Thorsten Kampe <thorsten@thorstenkampe.de>
Newsgroups comp.lang.python
Subject Customize help output from optparse (or argparse)
Date Thu, 12 May 2011 15:38:31 +0200
Lines 46
Message-ID <MPG.2836013fca77f958989809@news.individual.de> (permalink)
Mime-Version 1.0
Content-Type text/plain; charset="us-ascii"
Content-Transfer-Encoding 7bit
X-Trace individual.net MCQZx3dJuCG8+vmmF/PAYAWZf6phgnVeaQ0cf+U6ydjqztPLU=
Cancel-Lock sha1:PUT+QSR7t02KK887NWQWUJYlmNU=
User-Agent MicroPlanet-Gravity/3.0.4
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:5236

Show key headers only | View raw


Hi, 

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?

Thorsten

Back to comp.lang.python | Previous | NextNext 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