Comments (4)
I'm a little nervous about doing this for all help messages because sometimes
the
Python object used as a default doesn't make sense (e.g. a function object).
You can
use string format specifiers in the help messages though, like this::
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('--foo', type=int, default=123,
... help='Foo something (default: %(default)s)')
>>> parser.print_help()
usage: argparse.py [-h] [--foo FOO]
optional arguments:
-h, --help show this help message and exit
--foo FOO Foo something (default: 123)
Is that enough, or are you hoping for a help formatter that automatically adds
(default: xxx) to the end of everything with a non-None default?
Original comment by [email protected]
on 28 Mar 2009 at 2:09
from argparse.
I, for one, would like to see such a formatter. It should probably try to check
that
'%(default)' is not already in the string, though. I might want to override the
formatting for one argument.
Original comment by [email protected]
on 6 Jun 2009 at 10:06
from argparse.
Yeah, checking for '%(default)' makes a lot of sense. I'll try to add this
feature
before the next release of argparse. It'll probably come in the form of a new
subclass of HelpFormatter.
Original comment by [email protected]
on 10 Jun 2009 at 2:18
- Changed state: Accepted
from argparse.
I finally got around to this. There's now a ArgumentDefaultsHelpFormatter as of
r28
which adds ' (default: %(default)s)' to all the help strings where the argument
has a
default.
Original comment by [email protected]
on 13 Jul 2009 at 12:04
- Changed state: Fixed
from argparse.
Related Issues (20)
- Poll: why are you using argparse from pypi (or from here) these days? HOT 3
- How to filepath location as command line argument HOT 1
- What does the comments "We have to allow for ..." means? HOT 3
- parsing only a subset and leave all other checks undone HOT 3
- The description of optional arguments which takes values is not same as the (true/false) based ones since it's name is appearing twice. HOT 1
- argparse 1.2 incompatible with Python 3.1 HOT 10
- When -h is used, default values that fail should not matter HOT 2
- positional arguments before options cause all options to be in REMAINDER HOT 1
- Argparse is not testable with nosetest HOT 1
- `choices=[...]` overrides `nargs='*'` HOT 1
- Serious issues with nested mutex groups in help output HOT 2
- Bug with negative numbers in scientific notation HOT 1
- pypi version does not handle empty arguments when fromfile_prefix_chars set (python issue 12353) HOT 1
- .add_mutually_exclusive_group() only works when child of parser but not when a child of argument group HOT 1
- Argparse 1.4.0 doesn't have a wheel on PyPI: causes get-pip.py failures. HOT 2
- Is " if option_string.startswith(option_prefix): " a special design in _get_option_tuples()? HOT 3
- Issue with argument_group and required add_mutually_exclusive_group HOT 2
- AssertionError: assert ' '.join(pos_parts) == pos_usage HOT 3
- argparse WBN if default values displayed in -h message HOT 1
- argparse ArgumentParser(allow_abbrev=True) not documented on web HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from argparse.