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

Example 1: Checking Position After Reading a Few Lines

with open('data.txt', 'r') as f:
    f.readline()  # Read first line
    print(f.tell())  # Position after first line
    f.readline()  # Read second line
    print(f.tell())  # Position after second line
Output:
Position after first line
Position after second line

Example 2: Using tell() in Binary Mode

with open('binary_file.bin', 'rb') as f:
    f.read(10)  # Read 10 bytes
    print(f.tell())  # Output: 10

Example 4: Using tell() After Seeking to a Specific Position

with open('example.txt', 'r') as f:
    f.seek(5)  # Move the file pointer to the 5th byte
    print(f.tell())  # Output: 5
Output:
5

Moving the file position by seek()

File Append File Write
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer