[Python-checkins] cpython (merge 3.2 -> default): Merge #5088: document behavior of optparse defaults with 'append' action.

r.david.murray python-checkins at python.org
Sat Sep 8 22:48:39 CEST 2012


http://hg.python.org/cpython/rev/0c2bdd2c2032
changeset:   78892:0c2bdd2c2032
parent:      78890:7e1b46d3e24c
parent:      78891:8c60bb098eff
user:        R David Murray <rdmurray at bitdance.com>
date:        Sat Sep 08 16:46:10 2012 -0400
summary:
  Merge #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
@@ -1165,6 +1165,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