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