Program to find the cursor position in a file

In this python file program, we will find the cursor position in a file with the help of the below-given steps. Let’s consider we have readcontent.txt file with the below content.

				
					#readcontent.txt
Line1 : This is India.
Line2 : This is America.
Line3 : This is Canada.
Line4 : This is Australia.

				
			
Steps to solve the program
  1. Open the first file by using open(“readcontent.txt”).
  2. Read the lines using readlines().
  3. Print the position of the cursor using file.tell()
				
					# Open the file
file = open('readcontent.txt')
# Read lines of the file
file.readline()
# Print the position of the cursor
print("Position of a cursor in the file: ",file.tell())
				
			

Output :

Position of a cursor in the file: 23

 

 

count the total number of special characters in a file.

move the cursor to a specific position in a file.

Leave a Comment