
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2015-02-02 14:23 bythe.mulhern, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 13305 | merged | BTaskaya,2019-05-14 02:41 | |
| Messages (5) | |||
|---|---|---|---|
| msg235260 -(view) | Author: the mulhern (the.mulhern) | Date: 2015-02-02 14:23 | |
As well as the append action it would be convenient for there to be an extend action.This is kind of useful to allow something like:parser.add_argument("--foo", action="extend", nargs="+", type=str)givenparser.parse_args("--foo f1 --foo f2 f3 f4".split())to result in["f1", "f2", "f3", "f4"].The action "append" results in[["f1"], ["f2", "f3", "f4"]]And action store in["f2", "f3", "f4"].It is easy to write a custom action, but it feels like a fairly common requirement.Probably it would make sense to extend the default, similarly to how append behaves. | |||
| msg238936 -(view) | Author: paul j3 (paul.j3)*![]() | Date: 2015-03-22 20:21 | |
My opinion is that this is an unnecessary addition.Reasons:- it is easy to add as a custom action class- I haven't seen other requests for it- the append retains information about the argument strings that extend looses- it is easy flatten the appended attribute, e.g with a simple loop or a flattener like 'list(itertools.chain(*ll))' | |||
| msg238942 -(view) | Author: Wolfgang Maier (wolma)* | Date: 2015-03-22 21:19 | |
> - I haven't seen other requests for itFor the record, an Extend custom action class is one of very few such classes I have ever written for argparse for exactly the OP's usecase, i.e., it is useful for any parser that should accept the same option multiple times, while accepting multiple arguments each time.It *is* very simple to implement (and that's why I never asked for it as a feature), but only once you've understood custom action classes, which are not exactly for beginners.All in all, I'm +1 on the request. | |||
| msg342952 -(view) | Author: Guido van Rossum (gvanrossum)*![]() | Date: 2019-05-20 20:29 | |
I've felt the need for this myself. | |||
| msg343076 -(view) | Author: miss-islington (miss-islington) | Date: 2019-05-21 17:47 | |
New changesetaa32a7e1116f7aaaef9fec453db910e90ab7b101 by Miss Islington (bot) (Batuhan Taşkaya) in branch 'master':bpo-23378: Add an extend action to argparse (GH-13305)https://github.com/python/cpython/commit/aa32a7e1116f7aaaef9fec453db910e90ab7b101 | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:12 | admin | set | github: 67567 |
| 2019-05-21 17:53:34 | gvanrossum | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2019-05-21 17:47:45 | miss-islington | set | nosy: +miss-islington messages: +msg343076 |
| 2019-05-20 20:29:04 | gvanrossum | set | nosy: +gvanrossum messages: +msg342952 |
| 2019-05-14 10:36:02 | matrixise | set | versions: + Python 3.8, - Python 3.5 |
| 2019-05-14 02:41:32 | BTaskaya | set | keywords: +patch stage: needs patch -> patch review pull_requests: +pull_request13215 |
| 2015-03-23 06:15:46 | berker.peksag | set | nosy: +berker.peksag stage: needs patch versions: - Python 3.4, Python 3.6 |
| 2015-03-22 21:19:46 | wolma | set | nosy: +wolma messages: +msg238942 |
| 2015-03-22 20:21:12 | paul.j3 | set | nosy: +paul.j3 messages: +msg238936 |
| 2015-02-02 14:23:10 | the.mulhern | create | |