How to Read Only Parts of File in Python


In this example we will show how to read only parts of the file in Python.

Source Code

f = open('myfile.txt', 'r', encoding='utf-8')
text = f.read(10)
print(text)

Output:

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