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 has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science and Computer Science at Teachoo