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

Discussion in 'Python' started by Tim Chase, Aug 16, 2012.

  1. Tim Chase

    Tim Chase Guest

    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
     
    Tim Chase, Aug 16, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ethan Furman

    API design question for dbf.py

    Ethan Furman, Jul 6, 2012, in forum: Python
    Replies:
    0
    Views:
    170
    Ethan Furman
    Jul 6, 2012
  2. Ethan Furman
    Replies:
    7
    Views:
    175
    Ethan Furman
    Aug 16, 2012
  3. Ethan Furman
    Replies:
    0
    Views:
    129
    Ethan Furman
    Aug 16, 2012
  4. Tim Chase
    Replies:
    0
    Views:
    140
    Tim Chase
    Aug 16, 2012
  5. MRAB
    Replies:
    0
    Views:
    161
Loading...

Share This Page