What are the differences between readline() and readlines() in Selenium with python?



The differences between readline() and readlines() methods are listed below.

readlines()

  • 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.

readline()

  • 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.

Example

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()
Updated on: 2020-07-29T07:15:42+05:30

11K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements