一,读取文件
#读取文件
f = open("aa.txt","r")
#打印文件内容
print(f.read())
#关闭文件
f.close()
二,异常
#读取文件
f = None
try:
f = open("test.txt", "r")
print(f.read())
except BaseException:
print("文件没有找到")
finally:
if f is not None:
f.close()
三,with as语法
#读取文件
with open("aa.txt","r") as f:
print(f.read())
f.close()