[Python-checkins] cpython (2.7): closes #5088: document behavior of optparse defaults with 'append' action.
r.david.murray
python-checkins at python.org
Sat Sep 8 22:48:40 CEST 2012
http://hg.python.org/cpython/rev/79f6d4aff39d
changeset: 78893:79f6d4aff39d
branch: 2.7
parent: 78886:fca48971ac35
user: R David Murray <rdmurray at bitdance.com>
date: Sat Sep 08 16:47:24 2012 -0400
summary:
closes #5088: document behavior of optparse defaults with 'append' action.
files:
Doc/library/optparse.rst | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/Doc/library/optparse.rst b/Doc/library/optparse.rst
--- a/Doc/library/optparse.rst
+++ b/Doc/library/optparse.rst
@@ -1168,6 +1168,17 @@
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`]
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list