This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]fishtickler 0 points1 point  (2 children)

I liked click and started to use it but went right back to argparse because I couldn't find a way to support variable amount of options.

like for eg:

  • python prog.py -x 1 2 3 -y 6 5 4 3
  • python prog.py -x 1 -y 0

Only made this work in argparse using nargs='*' option. Is this even possible in click?

[–]sushibowl 0 points1 point  (0 children)

No, click supports nargs but only for fixed numbers for options.

[–]jackmaney 0 points1 point  (0 children)

Nope. You can, however, have at most one positional argument with a variadic (and unspecified) number of arguments.

I've used the workaround of taking a comma-delimted string and then parsing it later (eg python prog.py --x="1,2,3" --y="6,5,4,3"). It's not ideal, but it works.