I'm having a problem with 'os.path.getmtime'.
I've been doing some research into generating '.pyc' files and I am able to retrieve the source modification time (in seconds) as recorded in the '.pyc' file.
It is merely the second set of four bytes unpacked as a long integer.
import random, sys, os, struct #Points to the random.pyc module. testfilepath = os.path.join(sys.prefix, 'lib', 'random' + os.extsep + 'pyc') istream = open(testfilepath, 'rb') #Read and discard the first four bytes (the magic pyc identifier). istream.read(4) #The last modification time of the source according to the file. modtime = istream.read(4) istream.close() #Convert the bytes to an integer. modtime = struct.unpack('L', modtime) print('According to the pyc file the time the source file was last modified measured in the number of seconds from the last epoch is:') print(modtime) print('Retrieving source modification time using os.path.getmtime.') #Points to the random.py module. sourcefilepath = os.path.join(sys.prefix, 'lib', 'random' + os.extsep + 'py') print('According to os.path.getmtime the time the source file was last modified measured in the number of seconds from the last epoch is:') print(os.path.getmtime(sourcefilepath))
Oddly for me, the pyc time is one hour behind the time returned by os.path.getmtime. I suspect it is because of wonky dst errors. I'm using Windows XP SP3. I'd appreciate it if you would execute this code and report your results as well as your os and maybe suggest general purpose solutions to this problem.
Edited 6 Years Ago by lrh9: n/a