how to count lines in a file ?

Bengt Richter bokr at oz.net
Sat Jul 27 16:25:27 EDT 2002


On Sat, 27 Jul 2002 12:10:07 +0300, Kristian Ovaska <kristian.ovaska at helsinki.fi> wrote:

>bokr at oz.net (Bengt Richter):
>[f.readlines(N)]
>>That bothers me. ISTM it should return as many lines as
>>will fit in N bytes, but no more. Otherwise you have no
>>memory use protection against a single monster line
>
>You can't have complete protection in any case: what if there is a
>line of length > N? (Or length >> N...)
>
It wouldn't be returned. Lines up to it would be returned, unless it
was the first line about to be read. Then I think an exception would
be appropriate. You could catch it if you wanted to investigate with
ordinary read(n).

Regards,
Bengt Richter



More information about the Python-list mailing list