- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to read complete text file line by line using Python?
The read function reads the whole file at once. You can use the readlines function to read the file line by line.
You can use the following to read the file line by line:
f = open('my_file.txt', 'r+') for line in f.readlines(): print line f.close()
You can also use the with...open statement to open the file and read line by line.
with open('my_file.txt', 'r+') as f: for line in f.readlines(): print line
- Read file line by line using C++
- How to read an entire line from a text file using Python?
- What are some of the fastest way to read a text file line by line using C#?
- How to read a file from command line using Python?
- How to write a single line in text file using Python?
- How to read only 5 last line of the text file in PHP?
- How to read only the first line of a file with Python?
- How to Find Line Number of a Given Word in text file using Python?
- How to Delete Specific Line from a Text File in Python?
- How to read a text file in Python?
- Read last line from file in PHP
- How to read a Specific Line From a File in Linux?
- How to write into a file from command line using Python?
- How to read a number of characters from a text file using Python?
- How to display the complete text one word per line in C language?