file reading by record separator (not line by line)

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


--- George Sakkis <george.sakkis at gmail.com> 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 :)
>
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/521877

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__')
else
               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.
http://tv.yahoo.com/collections/265 



More information about the Python-list mailing list