Skip to content
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

Vector of any length as argument #118

Closed
DavidAce opened this issue Aug 24, 2021 · 3 comments
Closed

Vector of any length as argument #118

DavidAce opened this issue Aug 24, 2021 · 3 comments

Comments

@DavidAce
Copy link

DavidAce commented Aug 24, 2021

I wonder if argparse supports dynamic-length vector as arguments. Something like

  1. ./app --try-values 3.312 7.53 -71.2 ...

where the number of values is unknown at compile-time (i.e. without .nargs(#)).
I've been looking at the readme and other issues here, but all I can find is support for repeated arguments. If I understand correctly, this should work:

  1. ./app --try-values 3.312 --try-values 7.53 --try-values -71.2 ...

but this can quickly become tedious.

Is there a way to achieve version 1? It would be nice to do this with .nargs(-1) or .nargs(0) or an enum overload like .nargs(narg::dynamic).

@p-ranav
Copy link
Owner

p-ranav commented Aug 24, 2021

argparse provides support for gathering remaining args. See here: https://github.com/p-ranav/argparse#gathering-remaining-arguments. Hope this helps.

@DavidAce
Copy link
Author

Thanks! I think I can see how that solves the issue for a single vector, but I was really hoping to pass multiple vectors. Consider for instance

./app --rows=8,16,32 ... --columns=2,4,6...

If this is not possible now, is this something you would consider in a future version or in a pull request?

@p-ranav
Copy link
Owner

p-ranav commented Jun 22, 2022

@DavidAce There's a new release of argparse that will support this feature request. Hope this helps.

Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants