File Methods
tell()
Return the current stream position in the file.
file.tell()
file.tell() returns the current file pointer position as an integer offset from the beginning of the file.
Result
Returns
An integer representing the current byte offset.
Run it
Try it
Run it and change it
import tempfile
with tempfile.NamedTemporaryFile(mode='w+', delete=True) as f:
f.write('Hello')
print('Position after write:', f.tell()) Output
Press Run to see what it prints.Worth knowing
- Tracking progress: Useful for tracking read/write checkpoints, file sizes, or creating bookmarks in structured binary/text streams.