1f = open("filename", "r") #Load file in any mode that's able to read, ie r, r+, w+ etc
2
3#to get length
4len(f.readlines())
5
6#To iterate over each line
7for line in f.readlines(): #file.readlines(), splits the file into a list, where each element is a seperate line
8 print(line)
1fname = "test.txt"
2count = 0
3with open(fname, 'r') as f:
4 for line in f:
5 count += 1
6print("Total number of lines is:", count)
7