1

I've looked around on SO and various other websites and thought I figured this out, but apparently I didn't or I'm doing something wrong. Here is what I have tried:

pre = datetime.fromtimestamp(f)
pre = os.path.getmtime(f)
pre = fromtimestamp(f)

All three return the error:

TypeError: an integer is required

I did some digging and found this for what a lot of people have suggested:

os.path.getmtime(path)¶ 
Return the time of last modification of path. The return value is a number giving the number of seconds since the epoch (see the time module). Raise os.error if the file does not exist or is inaccessible.

New in version 1.5.2.

Changed in version 2.3: If os.stat_float_times() returns True, the result is a floating point number.

So now I am faced with the problem, how do I get it to be an integer value so I can compare this time with another after reading a file to determine if the file changed while parsing.

4

1 回答 1

1

os.path.getmtime takes a file path, not a file object:

>>> os.path.getmtime('/')
1359405072.0

If f is an open file, try passing in f.name.

于 2013-01-28T23:12:19.603 回答