[Tutor] Suggestions as to how to read a file in paragraphs
Alan Gauld
alan.gauld at blueyonder.co.uk
Wed Sep 1 23:01:31 CEST 2004
> You could read the file by lines and accumulate lines in a list
until you
> find a paragraph break. Then look at the accumulated lines and see
if you
> want to print it. Something like this (assuming a blank line is a
paragraph
> break):
Thats what I do in my cae study but its almost certainly slower than
reading
the entire file in one gulp then splitting by '\n\n' (ie a blank line)
to
get a list of paragraphs. But if memory is tight a loop with
xreadlines()
is probably best.
OTOH I haven't benchmarked any of this :-)
Alan G.
More information about the Tutor
mailing list