Check sibling questions

Write statements to display the position of the file pointer after reading two lines from a file linked to file object named fn.

 

Answer:

fn=open( "sample.txt" , 'r' )

for i in range( 0 , 2 , 1 ):

    l=fn.readline()

print( "The position of file pointer is at: " ,fn.tell())

 


Transcript

Question 9 Write statements to display the position of the file pointer after reading two lines from a file linked to file object named fn. Opening the text file in read mode and assigning it to file_object ‘fn’ Reads a line from the text file and assigns it to l The tell( ) method gives the position of file pointer Output

  1. Computer Science - Class 12
  2. Chapter 2 - File Handling in Python

About the Author

Davneet Singh

Davneet Singh is an IIT Kanpur graduate and has been teaching for 16+ years. At Teachoo, he breaks down Maths, Science and Computer Science into simple steps so students understand concepts deeply and score with confidence.

Many students prefer Teachoo Black for a smooth, ad-free learning experience.