[Tutor] What is the best way to count the number of lines in a huge file?

HY pythonpython@hotmail.com
Thu, 6 Sep 2001 15:38:43 +0900


What is the best way to count the number of lines in a huge file?
Say, I have a file which is 15MB in size.
I used:

file=open("data.txt","r")
n=0
for line in file.xreadlines():
    n+=0
print n

Is there a better/simpler way to do it?

Thanks a lot.

Hy