From: Mike H. <th...@bi...> - 2002-04-04 16:00:08
|
On Thu, Mar 14, 2002 at 11:51:45AM -0000, Dylan Browne wrote: > Is there any simple way to find the size of a file in Python. I get my file > by calling: > > f = open('myfile','r') > > I then want to determine wither the size in bytes, or the number of lines in > the file. Normally I would use f.length(), but as it is a pyfile I am a bit > stuck. Can you change the order a little bit? This way will work, without loading the file, which is a better if you are worried about size anyway: >>> import os,stat >>> os.stat("file1.xml")[stat.ST_SIZE] 841L C:\stuff\xml>dir file1.xml 03/21/2002 09:56a 841 file1.xml Also, it's good to have a bookmark on the official Python documentation, too: http://www.python.org/doc/current/ -- mikeh |