Newbie Needs help!!
Terry Reedy
tjreedy at udel.edu
Fri Oct 10 15:53:23 EDT 2003
"Rigga" <Rigga at noemail.com> wrote in message
news:h9Chb.60$X53.47 at news-binary.blueyonder.co.uk...
> Thanks for your reply, I was under the misunderstanding that I could
read
> the contents of the file and get the total number of lines the file
> contains in one go. Any pointers to how I can count the lines
manually??
Read the file with lines=readlines() instead of read(). Then
len(lines) is your count. If you really must read with all=read(),
then
count = all.count('\n') + (all[-1] != '\n')
Terry J. Reedy
More information about the Python-list
mailing list