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.

1
  • What is f in your code? Is it a path, or an open file? Commented Jan 28, 2013 at 23:09

1 Answer 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.

Sign up to request clarification or add additional context in comments.

2 Comments

I never get an integer value that's the problem. I can't compare the two times because they aren't integers. And besides I get something like 1316895144.181. And sorry. f was the path in my above examples.
Why can't you compare it with an integer? (If you really need an integer, and don't care about the extra subsecond precision, just use int(value) to make it an int).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.