top of page
Writer's pictureRajesh Singh

Tell function in python with example



Tell () function can be used to get the position of file handle and returns current position of file object where as Seek () function is used to change the position of the file handle to a given specific position in python. File handle such as a cursor which defines from where the data has to be read or written in the file.

Tell function takes no parameters and returns an integer value. Initially file pointer points to be beginning of the file. So the initial value of tell () is zero.

In other words we can say that tell () function is all about the returning of the current file position in a file stream. We can also change the current position by using seek () function.

Syntax: fileobj.tell ()

Example:

fileobj=open (“careerbodh.txt”, “r”)

print(“File Position: “,fileobj.tell())

print(“First lin : “, fileobj.readline())

print(“File Position :”, fileobj.tell())

print(“Second line:”, fileobj.readline())

print(“File Position:”, fileobj.tell())

fileobj.close()

Output:

File Position: 0

First line: Career Bodh Sansthan

File Position: 7

Second line: Career Bodh CCC

File Position: 13



86 views0 comments

Recent Posts

See All

For Loop MCQs in Python

Q1. What is the output of the following Python code? x={1:"X",2:"Y",3:"Z"} for i,j in x.items():     print(i,j,end=" ") A.    1 X 2 Y 3 Z...

留言


bottom of page