This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author monkeyman79
Recipients monkeyman79
Date 2021-01-27.23:52:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
This is spinoff from issue42973.

The purpose of this issue is to provide set of additional action classes for argparse, that could capture mutual relationship between command line arguments for more advanced parsers, where order of command line arguments is meaningful. It is hoped that this will work together with enhancement introduced in issue42973, providing also ability to capture relationship between options and positional parameters.

There will be four new action classes: 'extend_capture', 'append_capture', 'store_capture' and 'capture'.

Here are excerpts from documentation being prepared for the new action classes and an example of use:

* 'extend_capture' - Captures preceding argument values listed in the
  'capture' and 'capture_reset' keyword arguments and creates a dictionary object
  from those values, then adds actual command-line value to the dictionary using
  the 'key' keyword argument, finally the created dictionary is appended to the
  'dest' list. After capturing, all arguments listed in 'capture_reset' are reset
  to their default values. If there are more than one command-line values, a new
  dictionary object is created, and appended to the list for each value, with
  'capture_reset' arguments reset to their default values after first value is
  Example usage:

    >>> parser = argparse.ArgumentParser()
    >>> parser.add_argument("--load-addr", type=lambda s: int(s, 16))
    >>> parser.add_argument("--exec-addr", type=lambda s: int(s, 16))
    >>> parser.add_argument("--replace", action="store_true")
    >>> parser.add_argument("--file", nargs="*", action="extend_capture",
    ...     capture="*", capture_reset=["load_addr", "exec_addr"])
    >>> parser.parse_args("--replace --load-addr 1900 --exec-addr 8023 "
    ...     "--file CALC !BOOT".split())
    Namespace(load_addr=None, exec_addr=None, replace=True, file=[
        {'replace': True, 'exec_addr': 32803, 'load_addr': 6400, 'file': 'CALC'},
        {'replace': True, 'exec_addr': None, 'load_addr': None, 'file': '!BOOT'}])


The list of attributes to capture. This can be either a single attribute name,
a list (or other iterable type) of names or special value '*'. Name of
attribute associated with each argument is determined by the dest keyword
passed to add_argument method when the argument was
created. If capture_ is '*', all attributes are captured, except for this
argument's own value.

This keyword argument is valid only for 'extend_capture',
'append_capture', 'store_capture' and 'capture' actions.


The list of attributes to capture and reset to default value. As with capture,
this can be '*' to capture and reset all attributes except for this
argument's own value.

This keyword argument is valid only for 'extend_capture',
'append_capture', 'store_capture' and 'capture' actions.


The key to use for adding this argument's own command-line value to dictionary
of captured values. If this keyword argument is not specified, the dest is

This keyword argument is valid only for 'extend_capture',
'append_capture' and 'store_capture' actions.
Date User Action Args
2021-01-27 23:52:12monkeyman79setrecipients: + monkeyman79
2021-01-27 23:52:12monkeyman79setmessageid: <>
2021-01-27 23:52:12monkeyman79linkissue43046 messages
2021-01-27 23:52:12monkeyman79create