mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.14] GH-108009: Add clarification of parser and argument defaults in argparse docs (GH-124154) (#141084)
GH-108009: Add clarification of parser and argument defaults in argparse docs (GH-124154)
(cherry picked from commit 95f6e1275b)
Co-authored-by: Savannah Ostrowski <savannah@python.org>
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
This commit is contained in:
parent
5561837085
commit
00087dc466
1 changed files with 3 additions and 1 deletions
|
|
@ -2071,7 +2071,9 @@ Parser defaults
|
||||||
>>> parser.parse_args(['736'])
|
>>> parser.parse_args(['736'])
|
||||||
Namespace(bar=42, baz='badger', foo=736)
|
Namespace(bar=42, baz='badger', foo=736)
|
||||||
|
|
||||||
Note that parser-level defaults always override argument-level defaults::
|
Note that defaults can be set at both the parser level using :meth:`set_defaults`
|
||||||
|
and at the argument level using :meth:`add_argument`. If both are called for the
|
||||||
|
same argument, the last default set for an argument is used::
|
||||||
|
|
||||||
>>> parser = argparse.ArgumentParser()
|
>>> parser = argparse.ArgumentParser()
|
||||||
>>> parser.add_argument('--foo', default='bar')
|
>>> parser.add_argument('--foo', default='bar')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue