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

HY pythonpython@hotmail.com
Thu, 6 Sep 2001 16:28:42 +0900


Thanks for your respond. Great idea!

What if I want to use it on both Unix and Windows?
Is there a platform independent way to do it?

Hy

----- Original Message -----
From: "Praveen Pathiyil" <ppathiyi@cisco.com>
To: "HY" <pythonpython@hotmail.com>; <Tutor@python.org>
Sent: Thursday, September 06, 2001 4:06 PM
Subject: Re: [Tutor] What is the best way to count the number of lines in a
huge file?


> Hi,
>
> May be you can execute the Unix "wc -l" command using the popen2 command.
>
> stdout, stdin = popen2.popen2("wc -l <filename>")
> print stdout.read()
>
> -Praveen.
>
> ----- Original Message -----
> From: "HY" <pythonpython@hotmail.com>
> To: <Tutor@python.org>
> Sent: Thursday, September 06, 2001 12:08 PM
> Subject: [Tutor] What is the best way to count the number of lines in a
huge
> file?
>
>
> > 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
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>