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


Groups > comp.lang.python > #27120

Re: dbf.py API question concerning Index.index_search()

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'defaults': 0.05; 'matches': 0.07; 'override': 0.07; 'raised': 0.07; 'works.': 0.07; 'subject:question': 0.08; 'item,': 0.09; 'lost.': 0.09; 'subclass': 0.09; 'subject:()': 0.09; 'tuple': 0.09; 'cc:addr :python-list': 0.10; 'index': 0.13; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'message- id:@tim.thechases.com': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'subject:API': 0.16; 'wrote:': 0.17; 'saying': 0.18; 'error.': 0.21; 'cc:2**0': 0.23; 'raise': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'question': 0.27; '(as': 0.27; 'found.': 0.27; 'finds': 0.29; "i'm": 0.29; "skip:' 20": 0.32; 'interface,': 0.33; "can't": 0.34; 'done': 0.34; 'returning': 0.35; 'similar': 0.35; "didn't": 0.36; 'method': 0.36; 'anything': 0.36; 'should': 0.36; 'problems': 0.36; 'option': 0.37; 'usual': 0.37; 'quite': 0.37; 'subject:: ': 0.38; 'sure': 0.38; 'gives': 0.39; 'skip:n 10': 0.63; 'more': 0.63; 'fun': 0.64; 'here': 0.65; 'sounds': 0.71; 'special': 0.73; 'etc),': 0.84; 'furman': 0.84; 'received:50.22': 0.84; 'safer,': 0.84; 'you;': 0.84; 'ethan': 0.91
Date Wed, 15 Aug 2012 18:38:44 -0500
From Tim Chase <python.list@tim.thechases.com>
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111120 Icedove/3.1.16
MIME-Version 1.0
To Ethan Furman <ethan@stoneleaf.us>
Subject Re: dbf.py API question concerning Index.index_search()
References <502C3011.7070103@stoneleaf.us>
In-Reply-To <502C3011.7070103@stoneleaf.us>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - boston.accountservergroup.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - tim.thechases.com
X-Source
X-Source-Args
X-Source-Dir
Cc Python <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
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.3331.1345073858.4697.python-list@python.org> (permalink)
Lines 36
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1345073858 news.xs4all.nl 6843 [2001:888:2000:d::a6]:46671
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:27120

Show key headers only | View raw


On 08/15/12 18:26, Ethan Furman wrote:
>    .index_search(
>       match,
>       start=None,
>       stop=None,
>       nearest=False,
>       partial=False )
> 
> The defaults are to search the entire index for exact matches and raise
> NotFoundError if it can't find anything.
> 
> The question is what should the return value be?
> 
> I don't like the usual pattern of -1 meaning not found (as in
> 'nothere'.find('a')), so I thought a fun and interesting way would be to
> subclass long and override the __nonzero__ method to return True/False
> based on whether the (partial) match was found.  The main problems I see
> here is that the special return value reverts to a normal int/long if
> anything is done to it (adding, subtracting, etc), and the found status
> is lost.
> 
> The other option is returning a (number, bool) tuple -- safer, yet more
> boring... ;)


I'm not quite sure I follow...you start off by saying that it will
"raise NotFoundError" if it can't find anything.  So if it finds
something, just return it.  Because if it found the item, it gives
it to you; if it didn't find the item, it raised an error.  That
sounds like a good (easy to understand) interface, similar to how
string.index() works.

-tkc


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


Thread

Re: dbf.py API question concerning Index.index_search() Tim Chase <python.list@tim.thechases.com> - 2012-08-15 18:38 -0500

csiph-web