tell()
fob.tell()
Returns the current position of the file object.
In text mode file reading ( r )
At the beginning of the file.
fob=open('data1.txt','r')
print(fob.tell()) # 0
Using write mode
After writing data , the object will be at the end.
fob=open('data3.txt','w')
fob.write("Hello")
print(fob.tell()) # 5
fob.close()
We will add offset by using seek()
fob=open('data.txt','r')
fob.seek(5)
print(fob.tell()) # 5
By using the data.txt file given at file read()
fob=open('data.txt','br')
fob.seek(-5,2)
print(fob.tell()) # 76
fob=open('data.txt','r')
print(fob.readline())
print(fob.tell())
fob.close()
Output
This is first line
20
Moving the file position by seek() »
« File Append
File Write »
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com