file size

Robert W. Bill rbill at
Fri Sep 8 21:32:40 CEST 2000

On Fri, 8 Sep 2000, Keith Murphy wrote:
> how can i get the size of a file in python?
> i've done:
> 	self.logfile = open(filename, 'a')
> and i'd like to do this next:
> 	len_log = self.logfile.size()
> there something comparable?
> thanks,
> -->keith


two things come to mind.

os.stat is often used for size info.
i.e.-  	len_log = os.stat(filename)[6]

However, because you are opening self.logfile for appending,
you can use:
	self.logfile = open(filename, "a")
	len_log = self.logfile.tell()


More information about the Python-list mailing list