Skip to content

Instantly share code, notes, and snippets.

@dominics
Created March 6, 2012 09:29
Show Gist options
  • Save dominics/1985290 to your computer and use it in GitHub Desktop.
Save dominics/1985290 to your computer and use it in GitHub Desktop.
Open and read a file quickly in a loop
import sys
while True:
try:
with open('current/foo') as f:
contents = f.read()
if contents != 'a' and contents != 'b':
sys.exit("Couldn't read the contents")
except IOError:
sys.exit("Couldn't open the file")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment