Created
April 28, 2020 09:20
-
-
Save nimpy/de8b26ac2253556e39e4d37aba49309f to your computer and use it in GitHub Desktop.
Read a file line by line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
file = open('path/to/file', 'r') | |
count = 0 | |
while True: | |
line = file.readline() | |
if not line: | |
break | |
# do something here | |
count += 1 | |
file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I should be using the with statement. See: https://stackoverflow.com/a/48964410/4031135
TODO: update this gist accordingly.