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())

 

Question 9-Write statements to display - Teachoo.JPG

Learn in your speed, with individual attention - Teachoo Maths 1-on-1 Class


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

Ask a doubt
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 13 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.