size of a file

Harald Kirsch kirschh at lionbioscience.com
Wed Jul 25 03:55:56 EDT 2001


David Eppstein <eppstein at ics.uci.edu> writes:

> In article <3b5dd418_8 at news.newsgroups.com>,
>  "Janos Blazi" <jblazi at hotmail.com> 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
>     f.seek(0,2)    # go to end of file
>     fsize = f.tell()
>     f.close()

You probably might want to check if fn denotes a device file or named
pipe in which case this will fail.

  Harald.

-- 
----------------+------------------------------------------------------
Harald Kirsch   | kirschh at lionbioscience.com | "How old is the epsilon?"
LION bioscience | +49 6221 4038 172          |        -- Paul Erdös
       *** Please do not send me copies of your posts. ***



More information about the Python-list mailing list