Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41746

Re: Required arguments in argparse: at least one of a group

References <kikjpg$ch5$1@speranza.aioe.org>
Date 2013-03-23 16:27 +0000
Subject Re: Required arguments in argparse: at least one of a group
From Rob Day <robert.day@merton.oxon.org>
Newsgroups comp.lang.python
Message-ID <mailman.3648.1364056081.2939.python-list@python.org> (permalink)

Show all headers | View raw


I don't know about argparse, but if you use docopt
(http://docopt.org/) then this is easy to do with something like:

"""Usage:

finder.py --file <myfile> --dir <mydir>
finder.py --pattern <mypattern> --dir <mydir>
finder.py --file <myfile> --pattern <mypattern> --dir <mydir>
"""

On 23 March 2013 16:04, Marco <m.b@gmail.com> wrote:
> Is there the possibility using the argparse module to group two or more
> arguments in order to have at least one of them required? For instance, I
> would like to have not an error only in the following cases:
>
>   python finder.py --file myfile --dir mydir
>   python finder.py --pattern mypattern --dir mydir
>   python finder.py --file myfile --pattern mypattern --dir mydir
>
> where --dir is required, and --file _or_ --parser have to be specified. In
> other words, I want the parser prints an error message just in this case:
>
>   python finder.py --dir mydir
>
> Thanks in advance, Marco
> --
> Marco
> --
> http://mail.python.org/mailman/listinfo/python-list



-- 
Robert K. Day
robert.day@merton.oxon.org

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Required arguments in argparse: at least one of a group Marco <m.b@gmail.com> - 2013-03-23 17:04 +0100
  Re: Required arguments in argparse: at least one of a group Rob Day <robert.day@merton.oxon.org> - 2013-03-23 16:27 +0000
    Re: Required arguments in argparse: at least one of a group Marco <m.b@gmail.com> - 2013-03-24 21:02 +0100
  Re: Required arguments in argparse: at least one of a group rurpy@yahoo.com - 2013-03-24 14:41 -0700

csiph-web