file reading by record separator (not line by line)

Steve Howell showell30 at
Sat Jun 2 18:00:18 CEST 2007

--- George Sakkis <george.sakkis at> wrote:

> > It seems
> > like it would be fairly straightforward to do a
> quick
> > prototype implementation of this.  I'm off to work
> > soon, so I can't do it today, but maybe Sunday.
> I'm afraid I beat you to it :)

Well done.

Can I suggest a minor optimization?

Instead of this...

    def get_predicate(arg):
        return arg if callable(arg) else (
               arg.__eq__ if hasattr(arg,'__eq__')
               lambda item: item == arg)

...would this be faster?:

   if not callable(start):
       start = lambda arg: (arg.__eq__ if hasattr(...
   # then start iterating

Also, you haven't completely ruined my Sunday plans,
because I think I could enhance the cookbook example
by providing an alternative implementation that works
on finite lists, to show the less sophisticated (but
also less functional) approach to this problem.  But
maybe somebody will beat me to that as well...

We won't tell. Get more on shows you hate to love 
(and love to hate): Yahoo! TV's Guilty Pleasures list. 

More information about the Python-list mailing list