Re: CLI parsing—with `--help` text—`--foo bar`, how to give additional parameters to `bar`?

Mats Wichmann mats at python.org
Fri Oct 16 20:20:42 EDT 2020


On 10/15/20 5:09 PM, Samuel Marks wrote:
> Yes it’s my module, and I’ve been using argparse
> https://github.com/SamuelMarks/ml-params
> 
> No library I’ve found provides a solution to CLI argument parsing for my
> use-case.
> 
> So I’ll write one. But what should it look like, syntactically and
> semantically?

Jumping back to an earlier point in the thread...

There are an astonishing number of "argument parsers" for the Python
universe, but if none of them do what you want it's certainly not
illegal to write your own.  Reinventing the wheel is ok if existing
wheels don't work right on your vehicle - but do take the time check.
getopt, optparse, and argparse from the standard library have all
adopted some of the relatively well specified POSIX argument syntax.
Python has a heritage in the POSIX-y world, but not all systems
(Windows!) follow that model anyway. All have some quirks (I find
optparse and argparse irritating for some of the choices they've made).

If you haven't seen it, Dan Bader and his crew at the excellent
RealPython have a comparsion of some of them:

https://realpython.com/comparing-python-command-line-parsing-libraries-argparse-docopt-click

The thing is, if your situation is that you've looked at existing
implementations and don't like them, then it's hard to ask us here as a
group what a replacement should look like - by not liking what you've
seen you must have some model in your mind of what would look more sane
that you're comparing against, and we can't mind-read!


More information about the Python-list mailing list