argparse: delimiter for argparse list arguments

Jon Ribbens jon+usenet at unequivocal.eu
Tue Aug 3 16:55:43 EDT 2021


On 2021-08-03, Roel Schroeven <roel at roelschroeven.net> wrote:
> Jon Ribbens via Python-list schreef op 3/08/2021 om 17:48:
>> On 2021-08-03, Michael Torrie <torriem at gmail.com> 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.


More information about the Python-list mailing list