Python Read File Line by Line Into List

Jul 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))

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.