Skip to content

Instantly share code, notes, and snippets.

@nimpy
Created April 28, 2020 09:20
Show Gist options
  • Save nimpy/de8b26ac2253556e39e4d37aba49309f to your computer and use it in GitHub Desktop.
Save nimpy/de8b26ac2253556e39e4d37aba49309f to your computer and use it in GitHub Desktop.
Read a file line by line
file = open('path/to/file', 'r')
count = 0
while True:
line = file.readline()
if not line:
break
# do something here
count += 1
file.close()
@nimpy
Copy link
Author

nimpy commented Nov 3, 2020

I should be using the with statement. See: https://stackoverflow.com/a/48964410/4031135
TODO: update this gist accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment