Python File tell() and seek() Method
Master Python with 70+ Hands-on Projects and Get Job-ready - Learn Python
Program 1
# Program for tell() and seek()
import os
try:
if(os.path.isfile("d://indore/student1.txt")):
f=open("d://indore/student1.txt","r")
# print(f.tell())
# print(f.read(5))
# print(f.tell())
f.seek(2,0)
print(f.tell())
print(f.read(5))
# f.seek(0,0)
# print(f.tell())
# print(f.read(5))
# f.seek(0,1)
# print(f.tell())
# print(f.read(5))
f.close()
else:
print("File not found")
except Exception as obj:
print(obj)
If you are Happy with DataFlair, do not forget to make us happy with your positive feedback on Google

