file reading by record separator (not line by line)

George Sakkis george.sakkis at gmail.com
Sat Jun 2 15:24:13 CEST 2007


On Jun 1, 7:00 am, Steve Howell <showel... at yahoo.com> wrote:
> --- Tijs <tijs_n... at bluescraper.nl> wrote:
>
> > Yes, or a single one that takes a wide range of
> > construction possibilities,
> > like strings, lambdas or regexes in various keyword
> > parameters.
>
> > BlockReader(f, start='>')
> > BlockReader(f, start=re.compile('>|<'), end='---')
> > BlockReader(f, start=lambda x: x.startswith('>'))
>
> Definitely.  I like your idea for regexes that you
> just pass the method in, rather than the regex.  It
> means fewer variations, and it also leads to slightly
> more explicit code from the user, without being too
> cumbersome.
>
> Do you have any free time on your hands?  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

George




More information about the Python-list mailing list