Re: argparse: delimiter for argparse list arguments
Jon Ribbens via Python-list schreef op 3/08/2021 om 22:55: >> Loads of git commands do this. e.g. commit, diff, log, status, etc. >> It's not completely unlike what you're describing above, which is >> already supported automatically by argparse. > > Commands like git commit do not use '--' to separate two lists, but as > Dan and Sven said to separate options from arguments, That is not quite correct. Check out 'git diff' for example - it takes as position arguments zero, one, or two commit hashes followed by zero or more pathnames. You can use '--' to separate these two lists, because of course sometimes a pathname can be indistinguishable from a commit hash. Ah yes, I stand corrected, git diff indeed uses -- to separate two lists (commits and paths). -- "Too often we hold fast to the cliches of our forebears. We subject all facts to a prefabricated set of interpretations. Too often we enjoy the comfort of opinion without the discomfort of thought." -- John F Kennedy -- https://mail.python.org/mailman/listinfo/python-list
Re: argparse: delimiter for argparse list arguments
On 2021-08-03, Roel Schroeven wrote: > Jon Ribbens via Python-list schreef op 3/08/2021 om 17:48: >> On 2021-08-03, Michael Torrie wrote: >> > On 8/2/21 1:43 PM, Sven R. Kunze wrote: >> >> maybe, I am missing something here but is it possible to specify a >> >> delimiter for list arguments in argparse: >> >> >> >> https://docs.python.org/3/library/argparse.html >> >> >> >> Usually, '--' is used to separate two lists (cf. git). >> > >> > I've not seen this syntax in git. Are you referring the the double and >> > triple dot notation git uses? Can you give me an example of how git >> > uses -- as a list separator? >> >> Loads of git commands do this. e.g. commit, diff, log, status, etc. >> It's not completely unlike what you're describing above, which is >> already supported automatically by argparse. > > Commands like git commit do not use '--' to separate two lists, but as > Dan and Sven said to separate options from arguments, That is not quite correct. Check out 'git diff' for example - it takes as position arguments zero, one, or two commit hashes followed by zero or more pathnames. You can use '--' to separate these two lists, because of course sometimes a pathname can be indistinguishable from a commit hash. -- https://mail.python.org/mailman/listinfo/python-list
Re: argparse: delimiter for argparse list arguments
On Wed, Aug 4, 2021 at 7:07 AM Sven R. Kunze wrote: > > It could be but I've seen them used somewhere else. > > I wouldn't bikeshed on this yet, as I haven't found a way to do this so > far. Let's imagine the following parser: > > parser.add_argument('things',action='append') > parser.add_argument('stuff',action='append') > > At least from my point of view, I don't any way to separate both lists > on this command call: > > > cool-script.py thing1 thing2 stuff1 stuff2 > > > Do I miss something here? > I'd probably design it like this: cool-script.py --things thing1 thing2 --stuff stuff1 stuff2 which argparse already handles. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: argparse: delimiter for argparse list arguments
It could be but I've seen them used somewhere else. I wouldn't bikeshed on this yet, as I haven't found a way to do this so far. Let's imagine the following parser: parser.add_argument('things',action='append') parser.add_argument('stuff',action='append') At least from my point of view, I don't any way to separate both lists on this command call: cool-script.py thing1 thing2 stuff1 stuff2 Do I miss something here? Best Sven On 03.08.21 01:49, Dan Stromberg wrote: Isn't -- usually used to signal the end of options? On Mon, Aug 2, 2021 at 12:52 PM Sven R. Kunze <mailto:srku...@mail.de>> wrote: Hi everyone, maybe, I am missing something here but is it possible to specify a delimiter for list arguments in argparse: https://docs.python.org/3/library/argparse.html <https://docs.python.org/3/library/argparse.html> Usually, '--' is used to separate two lists (cf. git). Cheers, Sven -- https://mail.python.org/mailman/listinfo/python-list <https://mail.python.org/mailman/listinfo/python-list> -- https://mail.python.org/mailman/listinfo/python-list
Re: argparse: delimiter for argparse list arguments
Jon Ribbens via Python-list schreef op 3/08/2021 om 17:48: On 2021-08-03, Michael Torrie wrote: > On 8/2/21 1:43 PM, Sven R. Kunze wrote: >> maybe, I am missing something here but is it possible to specify a >> delimiter for list arguments in argparse: >> >> https://docs.python.org/3/library/argparse.html >> >> Usually, '--' is used to separate two lists (cf. git). > > I've not seen this syntax in git. Are you referring the the double and > triple dot notation git uses? Can you give me an example of how git > uses -- as a list separator? Loads of git commands do this. e.g. commit, diff, log, status, etc. It's not completely unlike what you're describing above, which is already supported automatically by argparse. Commands like git commit do not use '--' to separate two lists, but as Dan and Sven said to separate options from arguments, even if the arguments start with '-' (like many other programs -- I think this is standard in GNU). If you're 100% certain that none of the filenames start with '-', you can leave out '--' without any change in behavior. Especially when scripting and/or using wildcards it's best always to use that '--' to avoid nasty surprises. $ git commit -m "hello" -- hello.py is exactly the same as $ git commit -m "hello" hello.py It's just that the former is safer to use, because it properly works even in cases like $ git commit -m "hello" -- -hello.py whereas $ git commit -m "hello" -hello.py will likely not do what you expect. As https://git-scm.com/docs/git-commit says: > -- > Do not interpret any more arguments as options. -- "The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom." -- Isaac Asimov -- https://mail.python.org/mailman/listinfo/python-list
Re: argparse: delimiter for argparse list arguments
On 2021-08-03, Michael Torrie wrote: > On 8/2/21 1:43 PM, Sven R. Kunze wrote: >> maybe, I am missing something here but is it possible to specify a >> delimiter for list arguments in argparse: >> >> https://docs.python.org/3/library/argparse.html >> >> Usually, '--' is used to separate two lists (cf. git). > > I've not seen this syntax in git. Are you referring the the double and > triple dot notation git uses? Can you give me an example of how git > uses -- as a list separator? Loads of git commands do this. e.g. commit, diff, log, status, etc. It's not completely unlike what you're describing above, which is already supported automatically by argparse. -- https://mail.python.org/mailman/listinfo/python-list
Re: argparse: delimiter for argparse list arguments
On 8/2/21 1:43 PM, Sven R. Kunze wrote: > Hi everyone, > > maybe, I am missing something here but is it possible to specify a > delimiter for list arguments in argparse: > > https://docs.python.org/3/library/argparse.html > > Usually, '--' is used to separate two lists (cf. git). I've not seen this syntax in git. Are you referring the the double and triple dot notation git uses? Can you give me an example of how git uses -- as a list separator? Typically -- on a command line means that's the end of the any special switches and anything else, even if it looks like a command-line switch, should not be parsed, and passed straight through as a normal parameter. -- https://mail.python.org/mailman/listinfo/python-list
Re: argparse: delimiter for argparse list arguments
Isn't -- usually used to signal the end of options? On Mon, Aug 2, 2021 at 12:52 PM Sven R. Kunze wrote: > Hi everyone, > > maybe, I am missing something here but is it possible to specify a > delimiter for list arguments in argparse: > > https://docs.python.org/3/library/argparse.html > > Usually, '--' is used to separate two lists (cf. git). > > Cheers, > Sven > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
argparse: delimiter for argparse list arguments
Hi everyone, maybe, I am missing something here but is it possible to specify a delimiter for list arguments in argparse: https://docs.python.org/3/library/argparse.html Usually, '--' is used to separate two lists (cf. git). Cheers, Sven -- https://mail.python.org/mailman/listinfo/python-list