Class - 12 CBSE Computer Science Important File Handling Questions 2025
Write a function to insert a sentence in a text file, assuming that text file is very big and can't fit in computer's memory.
Python Data Handling
1 Like
Answer
Let the file "insert.txt" include the following sample text:
Bees hum
leaves rustle
Waves crash
nature's voice whispers
def insert_sentence(file_path, sentence):
file = open(file_path, 'a')
file.write(sentence + '\n')
file.close()
insert_sentence("insert.txt", "life's essence glimmers")
The "insert.txt" file includes following text:
Bees hum
leaves rustle
Waves crash
nature's voice whispers
life's essence glimmers
Answered By
2 Likes