from __future__ import with_statement with open("x.txt") as f: data = f.read()