CBSE Class 12 Computer Science Question 113 of 145

File Handling — Question 9

Back to all questions
9
Question

Question 9

Write a method in Python to read the content from a text file diary.txt line by line and display the same on screen.

Answer
def diary_content(f):
    myfile = open(f, "r")
    str = " "
    while str:
        str = myfile.readline()
        print(str, end = '')
    myfile.close()

diary_content("diary.txt")