讀文件:
with open("a.txt") as file:
data = file.read()
寫文件:
with open("a.txt") as f:
f.write("hello")
讀文件:
with open("a.txt") as file:
data = file.read()
寫文件:
with open("a.txt") as f:
f.write("hello")
本文先介紹with表達式,然後再試圖用with以及裝飾器等知識實現自己的ContextManagerwith可以幹什麼?我的理解是簡化try exce