Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.python

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 08-15-2012, 11:38 PM
Tim Chase
Guest
 
Posts: n/a
Default Re: dbf.py API question concerning Index.index_search()

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



Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 12:57 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.