-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
argparse.add_argument action parameter should allow value extend #67567
Comments
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) given parser.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. |
My opinion is that this is an unnecessary addition. Reasons:
|
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. |
I've felt the need for this myself. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: