number of lines in a file
Jeff Shannon
jeff at ccvcorp.com
Fri Mar 29 14:39:56 EST 2002
In article <slrnaa9b09.i04.philh at comuno.freeserve.co.uk>,
philh at comuno.freeserve.co.uk says...
> On Fri, 29 Mar 2002 06:36:14 -0800, Emile van Sebille <emile at fenx.com> wrote:
> >Joseph Youssef
> >> hello, I am nwe to Python and I'm trying to write this
> >> script but I need it to check how many lines is in
> >> the file and I don't know how so I'm hoping someone
> >> could tell me.
> >
> >len(open('/path/and/filename').readlines())
>
> Alternatively:
>
> os.system("wc -l %s" % filename)
>
Except that this is platform-specific for *nix, whereas
len(file.readlines()) works on all Python platforms.
--
Jeff Shannon
Technician/Programmer
Credit International
More information about the Python-list
mailing list