Read File Line by Line in Python

Posted on July 31, 2019 at 12:46 pm

Example to read a file line by line in python:

testsite_array = []
with open('file.txt') as my_file:
    for line in my_file:
        testsite_array.append(line)

Alternatively, you may want to use f.readlines():

with open('file.txt') as my_file:
    testsite_array = my_file.readlines()

Receive updates via email

Other Posts

Updated Posts