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


Picture showing the output of file when read without seek function





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


Picture showing the output of file when read with seek function



Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, June 30, 2020

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250