E
Ethan Furman
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~
.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~