Created
April 25, 2015 12:09
-
-
Save marcinwyszynski/785d56d1194b26a3f0ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import time | |
def open_unless_older_than(age_s, path): | |
meta = os.stat(path) # will throw IOError if path does not exist | |
if time.time() - meta.st_mtime > age_s: | |
raise IOError('File older than %d seconds' % age_s) | |
return open(path, r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment