Python Read File Line by Line Into List

July 14, 2019
filename = '...'

with open(filename) as f:
    items = list(f)

or

with open(filename) as f:
    items = f.readlines()

NOTE: \n is included for each line for both the solutions above.

or

Process each line and append to list

items = []
with open(filename) as f:
    for line in f:
        items.append(line.rstrip())
        # items.append(float(line))
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.