number of lines in a file

phil hunt philh at comuno.freeserve.co.uk
Fri Mar 29 13:01:46 EST 2002


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)


-- 
<"><"><"> Philip Hunt <philh at comuno.freeserve.co.uk> <"><"><">
"I would guess that he really believes whatever is politically 
advantageous for him to believe." 
                        -- Alison Brooks, referring to Michael
                              Portillo, on soc.history.what-if



More information about the Python-list mailing list