Total No. of "Records" in a File?

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Tue Aug 26 04:49:09 EDT 2008


W. eWatson a écrit :
> I have an ordinary text file with a CR at the end of a line, and two 
> numbers in each line. Is there some way to determine the number of lines 
> (records) in the file before I begin reading it?

How could you know how many times a given character appears in file 
without reading the whole file ?

You could of course store metadata about one file in another file[1], 
but then you'd have to read and parse this other file, and it might go 
out of sync.

[1] or at the begining of your 'data' file - but you still have to rad 
at least this part, and you still have the potential sync problem.

Or you could use a fixed-size binary format for your records, and try 
dividing the file size by the record size.

What's your concrete use case, exactly ?





More information about the Python-list mailing list