Skip to content

Instantly share code, notes, and snippets.

@marcinwyszynski
Created April 25, 2015 12:09
Show Gist options
  • Save marcinwyszynski/785d56d1194b26a3f0ab to your computer and use it in GitHub Desktop.
Save marcinwyszynski/785d56d1194b26a3f0ab to your computer and use it in GitHub Desktop.
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