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


Groups > comp.lang.python > #60231

Re: argparse feature request

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!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.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'parser': 0.07; 'python3': 0.07; 'see.': 0.07; 'exit': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'def': 0.12; 'arguments:': 0.16; 'false)': 0.16; 'kern': 0.16; 'main():': 0.16; 'optional': 0.16; 'positional': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:argparse': 0.16; 'underlying': 0.16; 'alpha': 0.16; 'wrote:': 0.18; 'subject:request': 0.19; 'import': 0.22; 'header:User-Agent:1': 0.23; 'interpret': 0.24; 'file.': 0.24; 'header:X-Complaints- To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'robert': 0.30; 'values.': 0.31; 'file': 0.32; 'url:python': 0.33; "i'd": 0.34; 'add': 0.35; 'url:org': 0.36; 'example,': 0.37; 'e.g.': 0.38; 'url:library': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'skip:- 10': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'range': 0.61; 'show': 0.63; 'our': 0.64; 'skip:f 50': 0.65; 'world': 0.66; 'sample': 0.67; 'believe': 0.68; 'default': 0.69; 'training': 0.77; '<<<': 0.84; 'eco': 0.84; 'programs:': 0.84; 'terrible': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Robert Kern <robert.kern@gmail.com>
Subject Re: argparse feature request
Date Fri, 22 Nov 2013 15:05:46 +0000
References <l6nrar$fss$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 213.1.240.226
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.1.1
In-Reply-To <l6nrar$fss$1@ger.gmane.org>
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3042.1385132759.18130.python-list@python.org> (permalink)
Lines 72
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1385132759 news.xs4all.nl 15886 [2001:888:2000:d::a6]:37679
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:60231

Show key headers only | View raw


On 2013-11-22 14:56, Neal Becker wrote:
> I use arparse all the time and find it serves my needs well.  One thing I'd like
> to see.  In the help message, I'd like to automatically add the default values.
>
> For example, here's one of my programs:
>
>   python3 test_freq3.py --help
> usage: test_freq3.py [-h] [--size SIZE] [--esnodB ESNODB] [--tau TAU] [--trials
> TRIALS]
>                       [--training TRAINING] [--sps SPS] [--si SI] [--alpha ALPHA]
>                       [--range RANGE] [--dfunc {gradient,delay}]
>                       [--mod
> {gaussian,qpsk,8psk,16apsk,32apsk,32dlr,64apsk,256apsk}]
>                       [--sym-freq-err SYM_FREQ_ERR] [--calibrate [CALIBRATE]]
>
> optional arguments:
>    -h, --help            show this help message and exit
>    --size SIZE
>    --esnodB ESNODB, -e ESNODB
>    --tau TAU, -t TAU
>    --trials TRIALS
>    --training TRAINING
>    --sps SPS
>    --si SI
>    --alpha ALPHA
>    --range RANGE
>    --dfunc {gradient,delay}
>    --mod {gaussian,qpsk,8psk,16apsk,32apsk,32dlr,64apsk,256apsk}
>    --sym-freq-err SYM_FREQ_ERR
>    --calibrate [CALIBRATE], --with-calibrate [CALIBRATE], --enable-calibrate
> [CALIBRATE], --no-calibrate [CALIBRATE], --without-calibrate [CALIBRATE], --
> disable-calibrate [CALIBRATE]
>
> What I'd like to see is:
>
> --size SIZE [2000]  <<< the default value is displayed

Use formatter_class=argparse.ArgumentDefaultsHelpFormatter

http://docs.python.org/2/library/argparse#argparse.ArgumentDefaultsHelpFormatter

E.g.

[git/mpstack]$ cat print_stacks.py
...
def main():
     import argparse
     parser = argparse.ArgumentParser(
         formatter_class=argparse.ArgumentDefaultsHelpFormatter)
     parser.add_argument('-p', '--percent', action='store_true', help='Show 
percentages.')
     parser.add_argument('file', help='The sample file.')
...

[git/mpstack]$ python print_stacks.py -h
usage: print_stacks.py [-h] [-p] file

positional arguments:
   file           The sample file.

optional arguments:
   -h, --help     show this help message and exit
   -p, --percent  Show percentages. (default: False)

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

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


Thread

Re: argparse feature request Robert Kern <robert.kern@gmail.com> - 2013-11-22 15:05 +0000

csiph-web