size of a file

David Eppstein eppstein at
Tue Jul 24 22:24:05 CEST 2001

In article <3b5dd418_8 at>,
 "Janos Blazi" <jblazi at> wrote:

> How can I find out the length of a file. I have a descriptor fd of the file
> (I am using the os module).

When I wanted to do this recently, I used

    f = open(fn)   # open file, fn is a string containing the filename,2)    # go to end of file
    fsize = f.tell()

I guess if you already have an fd you could skip the call to open() and 
seek back to the start in place of the close().

No doubt someone will tell me a better way to do this...
David Eppstein       UC Irvine Dept. of Information & Computer Science
eppstein at

More information about the Python-list mailing list