tell() function in file handling in python by R4R Team

- tell() is a file handling function in python programming language which are used to find the number of character in the text file.
- tell() operation will work when the other operation was work like read, write etc.

Syntax-

f=open(filename,mode)
f.tell()

Example-
file contain one line string like -"This is my file"
then tell() return 15


program-

#write data into file in multiple lines
f=open('myfile.txt','w')
f.write("This is the string")
f.close()

#read the file
f=open('myfile.txt','r')
print(f.read())
print(f.tell())
f.close()


output-

This is the string
18


-In this program, we write the string into the file, then we read the file by read() function then tell() function count the number of character in the file.

What tell() returns without read()-

program-

#write data into file in multiple lines
f=open('myfile.txt','w')
f.write("This is the string")
f.close()

#read the character
f=open('myfile.txt','r')
print(f.tell())
f.close()


output-

0


-In this program, tell() function return 0, that means it can not count any character, so it is clear that tell() function works only when other operation are performed.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!