Python 2.5.1 broken os.stat module

"Martin v. Löwis" martin at
Sat Jun 2 12:04:22 CEST 2007

> Reviewing my code it seems that it should still work with the 2.5.1 os.stat 
> changes however that does not appear to be the case.
> Timestamps reported by os.stat() are no longer correct and the results are 
> not even consistent.

I don't think this is the case. The results Python reports are correct
and consistent.

> In my first test case ALL 3 timestamps reported by Python are 1 hour less 
> than the actual timestamp on the file.

No. Instead, your *rendering* of the time-stamp is 1 hour less than
what you expect to see. This is because you render the time stamp
according to the current time zone (which is daylight-saving),
not according to the time-zone that was in effect when the file
was created (which was regular time).

> Assuming there is no error in the following code that prints out the 
> timestamps using the new return value from os.stat() then it would appear 
> that the 2.5.1 os.stat changes have a bug.
> print 'Creation    Time: %s' % time.strftime('%m/%d/%Y %H:%M:%S', 
> time.localtime(file_stats[stat.ST_CTIME]))
> print 'Last Access Time: %s' % time.strftime('%m/%d/%Y %H:%M:%S', 
> time.localtime(file_stats[stat.ST_ATIME]))
> print 'Last Write  Time: %s' % time.strftime('%m/%d/%Y %H:%M:%S', 
> time.localtime(file_stats[stat.ST_MTIME]))

It's not clear whether it's an error, however, localtime() does
something different from what dir does.


More information about the Python-list mailing list