Computer Science
Why is it required to close a file after performing the reading and writing operations on a file?
Python Data Handling
2 Likes
Answer
It is a good practice to close a file once we are done with the read and write operations. When we close a file, the system frees the memory allocated to it. Python ensures that any unwritten or unsaved data is flushed (written) to the file before it is closed. Therefore, it is always advised to close the file once our work is done.
Answered By
1 Like
Related Questions
How many file objects would you need to create to manage the following situations ? Explain.
(i) to process three files sequentially
(ii) to merge two sorted files into a third file.
Write the advantages of saving data in:
(a) Binary form
(b) Text form
When do you think text files should be preferred over binary files ?
Write a program that reads a text file and creates another file that is identical except that every sequence of consecutive blank spaces is replaced by a single space.