changeset: 78893:79f6d4aff39d branch: 2.7 parent: 78886:fca48971ac35 user: R David Murray date: Sat Sep 08 16:47:24 2012 -0400 files: Doc/library/optparse.rst description: closes #5088: document behavior of optparse defaults with 'append' action. diff -r fca48971ac35 -r 79f6d4aff39d Doc/library/optparse.rst --- a/Doc/library/optparse.rst Sat Sep 08 13:42:01 2012 -0400 +++ b/Doc/library/optparse.rst Sat Sep 08 16:47:24 2012 -0400 @@ -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`]

AltStyle によって変換されたページ (->オリジナル) /