File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -696,7 +696,7 @@ The add_argument() method
696
696
* const _ - A constant value required by some action _ and nargs _ selections.
697
697
698
698
* default _ - The value produced if the argument is absent from the
699
- command line.
699
+ command line and if it is absent from the namespace object .
700
700
701
701
* type _ - The type to which the command-line argument should be converted.
702
702
@@ -1006,6 +1006,14 @@ was not present at the command line::
1006
1006
>>> parser.parse_args([])
1007
1007
Namespace(foo=42)
1008
1008
1009
+ If the target namespace already has an attribute set, the action *default *
1010
+ will not over write it::
1011
+
1012
+ >>> parser = argparse.ArgumentParser()
1013
+ >>> parser.add_argument('--foo', default=42)
1014
+ >>> parser.parse_args([], namespace=argparse.Namespace(foo=101))
1015
+ Namespace(foo=101)
1016
+
1009
1017
If the ``default `` value is a string, the parser parses the value as if it
1010
1018
were a command-line argument. In particular, the parser applies any type _
1011
1019
conversion argument, if provided, before setting the attribute on the
You can’t perform that action at this time.
0 commit comments