Easy Tutorial
❮ Python Check Substring Present Given String Python Os Pathconf ❯

Python3 File tell() Method

Python3 File Methods


Overview

The tell() method returns the current position of the file, which is the current position of the file pointer.

Syntax

The syntax for the tell() method is as follows:

fileObject.tell()

Parameters

-

None

Return Value

Returns the current position of the file.

Example

The following example demonstrates the use of the tell() method:

The content of the file "tutorialpro.txt" is as follows:

1:www.tutorialpro.org
2:www.tutorialpro.org
3:www.tutorialpro.org
4:www.tutorialpro.org
5:www.tutorialpro.org

Loop through the file content:

Example (Python 3.0+)

#!/usr/bin/python3

# Open file
fo = open("tutorialpro.txt", "r+")
print("File name: ", fo.name)

line = fo.readline()
print("Data read: %s" % (line))

# Get the current file position
pos = fo.tell()
print("Current position: %d" % (pos))

# Close file
fo.close()

The output of the above example is:

File name:  tutorialpro.txt
Data read: 1:www.tutorialpro.org

Current position: 17

Python3 File Methods

❮ Python Check Substring Present Given String Python Os Pathconf ❯