file reading by record separator (not line by line)
Neil Cerutti
horpner at yahoo.com
Fri Jun 1 11:33:54 EDT 2007
On 2007-06-01, Tijs <tijs_news at bluescraper.nl> wrote:
> Steve Howell wrote:
>>>
>>> from blockread import BlockReader
>>>
>>> b = BlockReader(f, boundary='>')
>>> for block in b:
>>> # whatever
>>
>> Yep, I like this idea. You might have a few
>> variations:
>
> 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('>'))
>
> Maybe make variations for character-based readers and
> line-based readers.
I would prefer, "f.readlines(delim='>')" etc., a la C++
str::getline.
--
Neil Cerutti
More information about the Python-list
mailing list