dbf.py API question concerning Index.index_search()
- From: Ethan Furman <ethan@xxxxxxxxxxxx>
- Date: Wed, 15 Aug 2012 16:26:09 -0700
Indexes have a new method (rebirth of an old one, really):
.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.
match is the search criteria
start and stop is the range to search in
nearest returns where the match should be instead of raising an error
partial will find partial matches
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... ;)
Thoughts?
~Ethan~
.
- Follow-Ups:
- Re: dbf.py API question concerning Index.index_search()
- From: Hans Mulder
- Re: dbf.py API question concerning Index.index_search()
- From: Steven D'Aprano
- Re: dbf.py API question concerning Index.index_search()
- Prev by Date: Re: OT: Monty Python in Syria
- Next by Date: Re: dbf.py API question concerning Index.index_search()
- Previous by thread: Dynamically determine base classes on instantiation
- Next by thread: Re: dbf.py API question concerning Index.index_search()
- Index(es):