You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
argparse.add_argument action parameter should allow value extend #67567
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))'
wm75 commented on Mar 22, 2015
wm75mannequin
Mannequin
More actions
I haven't seen other requests for it
For 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.
Activity
themulhern commentedon Feb 2, 2015
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:
given
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.
paulj3 commentedon Mar 22, 2015
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))'
wm75 commentedon Mar 22, 2015
For 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.
gvanrossum commentedon May 20, 2019
I've felt the need for this myself.
miss-islington commentedon May 21, 2019
New changeset aa32a7e by Miss Islington (bot) (Batuhan Taşkaya) in branch 'master':
bpo-23378: Add an extend action to argparse (GH-13305)
aa32a7e