- seek() is a python function which set the file current location at the offset.
Syntax-
fileobject.seek(offset)
-Here fileobject is the object which points to the file location.
-offset is the numeric value,read/write operation starting from this position.
program-
#open a file and write
f=open('myfile.txt','w')
f.write("This is my data inside the file")
f.close()
#read file
f=open('myfile.txt','r')
print(f.read())
#open file and read with seek(11)
f=open('myfile.txt','r')
f.seek(11)
print(f.read())
#open file and read with seek(5)
f=open('myfile.txt','r')
f.seek(5)
print(f.read())
#open file and read with seek(20)
f=open('myfile.txt','r')
f.seek(20)
print(f.read())
#close file
f.close()
This is my data inside the file
data inside the file
is my data inside the file
de the file