summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2012-09-08 20:46:10 (GMT)
committerR David Murray <rdmurray@bitdance.com>2012-09-08 20:46:10 (GMT)
commit6f5578bab87e1d906a3b656cf4f5ac15461116c1 (patch)
tree2e4eb7afe834056bf438b9052c71e60e05a33ee4
parent230f6621fa80be4e4c43d5d5b8d3ea0e851a736a (diff)
parent14d66a98ed8674fd2e6ba2f04ddef694111011a2 (diff)
downloadcpython-6f5578bab87e1d906a3b656cf4f5ac15461116c1.zip
cpython-6f5578bab87e1d906a3b656cf4f5ac15461116c1.tar.gz
cpython-6f5578bab87e1d906a3b656cf4f5ac15461116c1.tar.bz2
Merge #5088: document behavior of optparse defaults with 'append' action.
-rw-r--r--Doc/library/optparse.rst11
1 files changed, 11 insertions, 0 deletions
diff --git a/Doc/library/optparse.rst b/Doc/library/optparse.rst
index add582e..6dc57bb 100644
--- a/Doc/library/optparse.rst
+++ b/Doc/library/optparse.rst
@@ -1165,6 +1165,17 @@ must specify for any option using that action.
options.tracks.append(int("4"))
+ The ``append`` action calls the ``append`` method on the current value of the
+ option. This means that any default value specified must have an ``append``
+ method. It also means that if the default value is non-empty, the default
+ elements will be present in the parsed value for the option, with any values
+ from the command line appended after those default values::
+
+ >>> parser.add_option("--files", action="append", default=['~/.mypkg/defaults'])
+ >>> opts, args = parser.parse_args(['--files', 'overrides.mypkg'])
+ >>> opts.files
+ ['~/.mypkg/defaults', 'overrides.mypkg']
+
* ``"append_const"`` [required: :attr:`~Option.const`; relevant:
:attr:`~Option.dest`]