Computer >> Computer tutorials >  >> Programming >> Python

How to read an entire line from a text file 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 first line:

f = open('my_file.txt', 'r+')
print(f.readline())