Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 14d66a9

Browse files
committed
#5088: document behavior of optparse defaults with 'append' action.
1 parent 8bdcdc2 commit 14d66a9

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

Doc/library/optparse.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,17 @@ must specify for any option using that action.
11651165

11661166
options.tracks.append(int("4"))
11671167

1168+
The ``append`` action calls the ``append`` method on the current value of the
1169+
option. This means that any default value specified must have an ``append``
1170+
method. It also means that if the default value is non-empty, the default
1171+
elements will be present in the parsed value for the option, with any values
1172+
from the command line appended after those default values::
1173+
1174+
>>> parser.add_option("--files", action="append", default=['~/.mypkg/defaults'])
1175+
>>> opts, args = parser.parse_args(['--files', 'overrides.mypkg'])
1176+
>>> opts.files
1177+
['~/.mypkg/defaults', 'overrides.mypkg']
1178+
11681179
* ``"append_const"`` [required: :attr:`~Option.const`; relevant:
11691180
:attr:`~Option.dest`]
11701181

0 commit comments

Comments
 (0)