Articles → Python → Seek Function In Python
Seek Function In Python
Purpose
Reading The File Without The Seek Function
#without seek function
myfile = open("c:\\temp\\gyan.txt", "r")
content = myfile.read()
print("Reading the content for first time", content)
content = myfile.read()
print("Reading the content for second time", content)
myfile.close()
Output
Reading The File With The Seek Function
#with seek function
myfile = open("c:\\temp\\gyan.txt", "r")
content = myfile.read()
print("Reading the content for first time", content)
myfile.seek(0)
content = myfile.read()
print("Reading the content for second time", content)
myfile.close()
Output