file size

Robert W. Bill rbill at digisprings.com
Fri Sep 8 15:32:40 EDT 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()
> 
> ...is there something comparable?
> 
> thanks,
> -->keith

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()
	

-robert




More information about the Python-list mailing list