Re:Tools I use: argparse builder
by anonymoushn on Thursday October 08, 2020 @09:35AM
(#24718961)
What issues do the pallets maintainers have?
Re:Tools I use: argparse builder
by metalliqaz on Thursday October 08, 2020 @10:01AM
(#24719151)
This 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.What 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 --).
Re:Tools I use: argparse builder
by metalliqaz on Thursday October 08, 2020 @11:51AM
(#24720286)
Yeah, 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>")
Also it avoids a pallets package, which is good because I prefer to avoid any unnecessary exposure to its maintainer.