Posted on 26th March 2023
You can use readlines() method to read a file line by line here is the example
L = ["Mindmajix\n", "Is\n", "Best\n"]
filex = open('myfile.txt', 'w')
filex.writelines(L)
filex.close()
filex = open('myfile.txt', 'r')
Lines = filex.readlines()
count = 0
for line in Lines:
print("Line{}: {}".format(count, line.strip()))
Output:
Line1: Mindmajix
Line2: Is
Line3: Best
STILL GOT QUERIES?
Copyright © 2013 - 2023 MindMajix Technologies