views:

69

answers:

2

Getting two different modification time when calculated from different Python versions on Windows XP.

Python2.4

C:\Copy of elisp>c:\python24\python
Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.getmtime("auto-complete-emacs-lisp.el")
1251684178
>>> ^Z

Python2.6

C:\Copy of elisp>C:\Python26\python
Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.getmtime("auto-complete-emacs-lisp.el")
1251687778.0
>>>

There is a difference of 3600 seconds reported by Python2.6 and Python2.4.

What is the reason of this strange behavior?

+2  A: 

There is a difference of 3600 seconds ...

This should be the kicker. It's a timezone problem, pure and simple.

Now all you have to do is find out why 2.4 and 2.6 are using different timezone information :-)

paxdiablo
The "What's New in Python 2.x" pages don't mention changes in either timezone or mtime() behaviour, so I'm going to guess it's Microsoft up to its old tricks, between MSC v.1310 and v.1500. A custom build of each with the same version, if that's possible, would be one way to see if that's the case.
Peter Hansen
Strangely enough, theres a few posts on the net complaining about this: http://www.velocityreviews.com/forums/t351183-os-path-getmtime-on-winxp.html for example.
paxdiablo
And http://coding.derkeiler.com/Archive/Python/comp.lang.python/2007-06/msg00000.html
paxdiablo
+2  A: 

It's a bug in Microsoft's implementation of the C standard library. Python 2.4 used to use the stdlib fstat call to get file information, and hence could end up an hour out in locales that use DST.

In Python 2.5 and later, os.stat calls the direct Win32-only API to get file information when running on Windows, resulting in the correct output. See this thread for more.

bobince
Also, this message: http://coding.derkeiler.com/Archive/Python/comp.lang.python/2007-06/msg00300.html
atzz