file size

Steve Holden sholden at holdenweb.com
Fri Sep 8 15:27:27 EDT 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
> 
Indeed there is.  You can do:

	import os
	len_log = os.stat(filename)[6]

This functionality is available on both UNIX and Windows.  To be more
nicely symbolic you could extend the example to:

	import os
	from stat import *
	len_log = os.stat(filename)[ST_SIZE]

which makes it a bit more obvious what's going on.

regards
 Steve
-- 
Helping people meet their information needs with training and technology.
703 967 0887      sholden at bellatlantic.net      http://www.holdenweb.com/



More information about the Python-list mailing list