1with open("file.txt") as file_in:
2 lines = []
3 for line in file_in:
4 lines.append(line)
1file1 = open('myfile.txt', 'r')
2Lines = file1.readlines()
3# usage:
4count = 0
5for line in Lines:
6 count += 1
7 print("Line{}: {}".format(count, line.strip()))
1file1 = open('myfile.txt', 'r')#open the file (mode read)
2count = 0 #used to count the lines
3
4for line in Lines:
5 line = file1.readline()#read a single line
6 if not line:
7 break
8 count += 1
9 print("Line{}: {}".format(count, line))#print the lines with their number
10