Checking a file's time stamp.

Christian Heimes lists at
Tue Aug 12 19:53:02 CEST 2008

William Purcell wrote:
> Hi all,
> I am wanting to check to see the last time a file was edited. For example, I
> have a directory containing two text files, file1.txt and file2.txt.   I
> want to be able to process these files but only if they have been edited
> since the last time they were processed. I think that I want to be able to
> check the time stamp of each file. Can anyone tell me how to do that or
> point me in a better direction of checking the last time a file was edited?

 >>> import os
 >>> stat = os.stat("/etc/passwd")
 >>> print stat
(33188, 362259, 2053L, 1, 0, 0, 1690, 1218550501, 1218118498, 1218118498)
 >>> dir(stat)
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', 
'__eq__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', 
'__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', 
'__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', 
'__repr__', '__rmul__', '__setattr__', '__str__', 'n_fields', 
'n_sequence_fields', 'n_unnamed_fields', 'st_atime', 'st_blksize', 
'st_blocks', 'st_ctime', 'st_dev', 'st_gid', 'st_ino', 'st_mode', 
'st_mtime', 'st_nlink', 'st_rdev', 'st_size', 'st_uid']
 >>> stat.st_mtime

More information about the Python-list mailing list