它应该关闭文件
__del__语句中的文件句柄,但是更好的方法是使用
with块:
def read_contents(file_path): with open(file_path, 'r') as f: return f.read()
有关更多信息,请参见http://docs.python.org/library/stdtypes.html#file.close。

它应该关闭文件
__del__语句中的文件句柄,但是更好的方法是使用
with块:
def read_contents(file_path): with open(file_path, 'r') as f: return f.read()
有关更多信息,请参见http://docs.python.org/library/stdtypes.html#file.close。