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
- Open the first file by using open(“readcontent.txt”).
- Read the lines using readlines().
- 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