+ 1
Why is it necessary to close the file?
Any explanation?
4 ответов
+ 3
it's is not necessary if you use your file once, your program works fine if you do not close it. But if you use more than once its needed to close your file. Although its always good and safer close it after use it.
+ 1
it saves the text file
+ 1
I think there is one more advantage in using "with". Suppose you are working with a series of large files, where you are reading the content of each file to memory and do some computation. If you forget to close each file properly, you may quickly run out of memory or you may cause the OS to do unnecessary swaps, which affects the system performance.
0
to free up memory used during file connection. just like when connect or disconnecting a rational db.