
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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()
Advertisements