開發板上電就會去掉用update_file函數。linux+Python2.7
def update_file(config): with open(FILE_PATH, "w") as fp: fp.write(config) return None
調試結果:
0、執行完打開文件,內容寫進去了。
1、執行完該函數後,不訪問該文件,直接斷電,重新上電後文件內容為空,write的內容並沒有寫進去。
2、write之後加上fp.flush後,同樣操作就能寫進去。
疑問:
with open不是會自動close嗎?為什麼函數都執行完成了,緩存區的內容為什麼還沒寫到文件中?
with open會自動關閉的話,在什麼時候關閉?