The differences between readline() and readlines() methods are listed below.
This method will read the entire content of the file at a time.
This method reads all the file content and stores it in the list.
This method reads up to the end of the line with readline () and returns a list.
This method will read one line in a file.
A new line character is left at the string end and is ignored for the last line provided the file does not finish in a new line.
This method reads up to the end of the line with readline() and returns a list.
Code Implementation with readline()
#open the file for read operation fl = open('pythonfile.txt') # reads line by line ln = fl.readline() while ln!= "": print(ln) ln = fl.readline() #close the file fl.close()
Code Implementation with readlines()
#open the file for read operation fl = open('pythonfile.txt') # reads line by line and stores them in list for ln in fl.readlines(): print(ln) #close the file fl.close()