5 ms·
I use click[1] for things that don't need the complexity/features of argparse, personally, which ends up saving a lot of time. [1] https://click.palletsproject
by anaphor 6y ago
I use click[1] for things that don't need the complexity/features of argparse, personally, which ends up saving a lot of time.
[1] https://click.palletsprojects.com/en/7.x/ https://click.palletsprojects.com/en/7.x/
- metalliqaz 6y agoFor things that don't require the complexity/features of argparse, I use sys.argv. Doesn't require any extra packages and other programmers have no trouble understanding the code. Also it avoids a pallets package, which is good because I prefer to avoid any unnecessary exposure to its maintainer.
- anonymoushn 6y agoWhat issues do the pallets maintainers have?
- metalliqaz 6y agoThis is HN not Reddit, so I will just say I personally don't like him and talk about sys.argv. Nearly every script I write only requires something like the following: for arg in sys.argv[1:]: if arg == '-v': ... if ...: print(f"Usage: {sys.argv[0]} -v ...") In the very rare occasion that I have an actually large command line project, argparse is built in and works fine.
- im3w1l 6y agoWhat I like about argparse is that it will handle stuff like --infile -v (-v means filename in this context since it's value of the infile parameter) or -- -v (-v is forced to be interpreted as positional in this case since it comes after --).
- metalliqaz 6y agoYeah, I would use argparse if I had to support something like that. To be honest, the extent of my command line parsing is almost always just this: try: infile = sys.argv[1] outfile = sys.argv[2] except IndexError: print(f"Usage: {sys.argv[0]} <infile> <outfile>")
- lou1306 6y agoMoreover, click provides a lot of additional CLI-related stuff (printing with colors, asking for input, progress bars) with IMHO pretty reasonable default behaviour. And it's really well-documented!
- nickjj 6y agoI normally use Click but sometimes argparse is great for CLI tools that have zero dependencies and aren't massive in scope. Since most systems have Python, distributing your argparse driven file means curling it down and making it executable instead of having to pip install things.
- ex_amazon_sde 6y agoClick lacks flexibility, requires almost the same amount of boilerplate than argparse, and add dependencies.