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



26 views0 comments

Recent Posts

See All

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 t

Slicing is a Python attitude that enables accessing parts of data from the given sequence like list, tuples etc. A slice object is created based on a set of indices. Slicing starts anywhere from list