+ 2
Need for the close function
Why is it necessary to use the close function. Doesn't Python automatically close the file after the program is run?
5 Respuestas
+ 1
Nope python doesn't do it for you, you can make it automatic with a try finally statement:
try:
#openfile, do something
finally: #no matter what happens
file.close()
+ 1
You can have statement like
--> with open(filename):
This will automatically close your file
+ 1
@Viswanathan , can you explain it Better? i didn't understand
0
you got to close it to make the file to be updated when you write it... it will be saved with the new text (when you are in writing mode)
0
the .close() is saving the changes you've done to the file