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

 

Question 9-Write statements to display - Teachoo.JPG

Introducing your new favourite teacher - Teachoo Black, at only ₹83 per month


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

CA Maninder Singh's photo - Expert in Practical Accounts, Taxation and Efiling

Made by

CA Maninder Singh

CA Maninder Singh is a Chartered Accountant for the past 12 years. He also provides Accounts Tax GST Training in Delhi, Kerala and online.