Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.002 X-Spam-Evidence: '*H*': 1.00; '*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; 'used.': 0.09; 'python': 0.11; 'def': 0.12; 'arguments:': 0.16; 'false)': 0.16; 'kern': 0.16; 'main():': 0.16; 'optional': 0.16; 'perfect.': 0.16; 'positional': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:argparse': 0.16; 'alpha': 0.16; 'wrote:': 0.18; 'options.': 0.19; 'subject:request': 0.19; 'seems': 0.21; 'import': 0.22; 'header:User-Agent:1': 0.23; 'file.': 0.24; 'header:X-Complaints-To:1': 0.27; "doesn't": 0.30; 'robert': 0.30; 'that.': 0.31; 'usually': 0.31; 'produces': 0.31; 'values.': 0.31; 'file': 0.32; 'thanks!': 0.32; 'option': 0.32; 'url:python': 0.33; "i'd": 0.34; 'problem': 0.35; 'add': 0.35; 'useful': 0.36; '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; 'anything': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'range': 0.61; 'show': 0.63; 'skip:f 50': 0.65; 'sample': 0.67; 'default': 0.69; 'training': 0.77; '<<<': 0.84; "it'd": 0.84; 'programs:': 0.84; 'received:139': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Neal Becker Subject: Re: argparse feature request Date: Fri, 22 Nov 2013 11:52:20 -0500 References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: exa2-in-fw-01-epn.hns.com User-Agent: KNode/4.11.3 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: 77 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1385139156 news.xs4all.nl 16009 [2001:888:2000:d::a6]:40738 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:60242 Robert Kern wrote: > 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) > Thanks! Almost perfect. Problem is, I don't usually bother to add help='help me' options. It seems that ArgumentDefaultsHelpFormatter doesn't do anything unless help='blah' option is used. Not sure what to do about that. Since python test_freq3.py -h produces useful messages without my adding help=... everywhere, it'd be nice if ArgumentDefaultsHelpFormatter would work here.