You can just iterate over each line in Python. Use the universal end of line mode, if you want Python to take care of the Windows / UNIX / Mac line, it automatically ends:
with open("mytextfile.txt", "rtU") as f: for line in f:
You do not need to take care of EOL / EOF yourself in this code example.
Note that the line variable includes line endings. If you do not want them, you can use line = line.rstrip() , for example.
source share