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

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <robertkday@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; '"""': 0.05; 'arguments': 0.07; 'parser': 0.07; 'python': 0.09; 'cc:addr:python-list': 0.10; 'url:)': 0.13; '--file': 0.16; 'argparse': 0.16; 'cases:': 0.16; 'specified.': 0.16; 'subject:argparse': 0.16; 'wrote:': 0.17; 'instance,': 0.17; 'subject:group': 0.17; 'sender:addr:gmail.com': 0.18; 'module': 0.19; 'cc:2**0': 0.23; 'least': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'possibility': 0.27; 'message-id:@mail.gmail.com': 0.27; 'prints': 0.29; 'url:mailman': 0.29; 'error': 0.30; 'url:python': 0.32; 'url:listinfo': 0.32; 'like:': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'robert': 0.35; 'something': 0.35; 'there': 0.35; 'but': 0.36; 'url:org': 0.36; 'two': 0.37; 'subject:: ': 0.38; 'where': 0.40; 'url:mail': 0.40; 'easy': 0.60; 'more': 0.63; 'day': 0.73; '2013': 0.84; 'subject:Required': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=x6VpT65NoBV1Zv2NdzWSvO+IAg0qPAkg8r6TkKWanbs=; b=c29s1NMyHsAsC5RiC4lTvkMQsxbb48R5WoKluYf+PPsqtyQxfSSzuwR5+XigbVF2KC F8yO/vQehIrp+IgcaqNKv0UBXwCTp8mOtvpU3aWLljjNilrivRImUJXlS7ZlW6TqOhJf 2ajAmz8grC6G18sbB2eRvAKoN3IC+UFnDeV3D11o6Im7envfw9NvRJr+8kfDHZ8VAu7D SShkcMKkAlBAA+0ZllLVr1gI02m4JVSyMn57Q6bSSRmbHl2hhG9oVMxJ6QUqJEgLkzI8 FkfakzUVxdBgBZf0Ri7h9ycCv4sx1G/JrGlB5/hjhLiMxmTmW0xdw0EknOn8v4fSS8pW 7K/g==
MIME-Version 1.0
X-Received by 10.224.94.4 with SMTP id x4mr363786qam.60.1364056073621; Sat, 23 Mar 2013 09:27:53 -0700 (PDT)
Sender robertkday@gmail.com
In-Reply-To <kikjpg$ch5$1@speranza.aioe.org>
References <kikjpg$ch5$1@speranza.aioe.org>
Date Sat, 23 Mar 2013 16:27:53 +0000
X-Google-Sender-Auth VMLwxLM5fDa81wIDeuNqPR_6OYI
Subject Re: Required arguments in argparse: at least one of a group
From Rob Day <robert.day@merton.oxon.org>
To Marco <m.b@gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Cc python-list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3648.1364056081.2939.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1364056081 news.xs4all.nl 6874 [2001:888:2000:d::a6]:33461
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:41746

Show key headers only | 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