From: R David Murray <rdmurray@bitdance.com> Date: Sat, 8 Sep 2012 20:45:35 +0000 (-0400) Subject: #5088: document behavior of optparse defaults with 'append' action. X-Git-Tag: v3.3.1rc1~813^2~106 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=14d66a98ed8674fd2e6ba2f04ddef694111011a2;p=python #5088: document behavior of optparse defaults with 'append' action. --- diff --git a/Doc/library/optparse.rst b/Doc/library/optparse.rst index add582efed..6dc57bb3a6 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`]