Articles → Python → Seek Function In Python

Seek Function In Python






Purpose





Reading The File Without 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()




Picture showing the output of file when read without seek function

Click to Enlarge




Reading The File With 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()


Picture showing the output of file when read with seek function

Click to Enlarge


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

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250