Is explicitly closing files important?
问题 In Python, if you either open a file without calling close() , or close the file but not using try - finally or the " with " statement, is this a problem? Or does it suffice as a coding practice to rely on the Python garbage-collection to close all files? For example, if one does this: for line in open("filename"): # ... do stuff ... ... is this a problem because the file can never be closed and an exception could occur that prevents it from being closed? Or will it definitely be closed at