How to Read One Line of File in Python


In this example we will show how to read one line of the file in Python.

Source Code

f = open('myfile.txt', 'r', encoding='utf-8')
text_line = f.readline()
print(text_line)

Output:

Hello World!
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments