python文件处理
文件处理
file = open("/tmp/foo.txt")
data = file.read()
file.close()
处理异常
file = open("/tmp/foo.txt")
try:
data = file.read()
finally:
file.close()
with可以很好的处理上下文环境产生的异常
with open("/tmp/foo.txt") as file:
data = file.read()