這個問題在這里已經有了答案: 是否需要關閉與它們無關的檔案? (6 個回答) 6 天前關閉。
在python中,如果我打開一個檔案:
file = open('file.txt','r')
// read the file and stuff
file = None // does this close the file and free up resources?
然后將其設定為其他內容,該檔案會被關閉嗎?這樣做會有什么壞處嗎?
我知道 'file.close()' 會這樣做,但我想知道我是否可以將其設定為其他內容。
uj5u.com熱心網友回復:
除非您使用with open.
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/360996.html
上一篇:錯誤com.fasterxml.jackson.core.JsonParseException:無法識別的令牌
下一篇:完美正方形Python
