October 2021

Read A File Line By Line In Python

You can just use the file handle with a for loop.

for file in source_files:
    with open(file) as _file:
        for line in _file:
            print(line)

# TODO: Also look at:
# for line in _file.read().splitlines():
end of line