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: 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: References: 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 To: Marco Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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 --dir finder.py --pattern --dir finder.py --file --pattern --dir """ On 23 March 2013 16:04, Marco 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