Skip to content

Instantly share code, notes, and snippets.

@Kwpolska
Created January 15, 2015 17:32
Show Gist options
  • Save Kwpolska/f845da8b55056f5fb0fe to your computer and use it in GitHub Desktop.
Save Kwpolska/f845da8b55056f5fb0fe to your computer and use it in GitHub Desktop.
with in for
import io
files = ['foo', 'bar', 'baz']
for fn in files:
with io.open(fn, 'r', encoding='utf-8') as fh:
print('file {0}:'.format(fn))
print(fh.read())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment