Skip to content

Instantly share code, notes, and snippets.

@Yunkou
Created August 30, 2017 18:54
Show Gist options
  • Save Yunkou/0a5f41bb553f765560e0b056c443a6a0 to your computer and use it in GitHub Desktop.
Save Yunkou/0a5f41bb553f765560e0b056c443a6a0 to your computer and use it in GitHub Desktop.
File reading with ‘with’
# The bad way
f = open('pimpin-aint-easy.txt')
text = f.read()
for line in text.split('\n'):
print(line)
f.close()
# The good way
with open('pimpin-aint-easy.txt') as f:
for line in f:
print(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment