Skip to main content

tell()

The tell() function from File Methods in Python returns the current position of the file read/write pointer within the file. It indicates the next byte that will be read or written. The position is an integer value representing the number of bytes from the beginning of the file.

Parameter Values

This function does not accept any parameters.

Return Values

The tell() method returns an integer representing the current file position.

How to Use tell() in Python

Example 1:

The tell() method returns the current file position, represented as an integer giving the number of bytes from the beginning of the file.

with open('example.txt', 'r') as file:
    position = file.tell()
    print(position)
Example 2:

The tell() method is commonly used to store the current file position for later use or to keep track of the reading progress in a file.

with open('data.bin', 'rb') as file:
    current_position = file.tell()
    print(f'Current position: {current_position}')