FileNotFoundError的处理代码:
filename = 'tom.txt'#tom这个文件是不存在的
try:
with open(filename) as file:
content = file.read()
except FileNotFoundError:#文件不能找到的异常处理
print("Sorry!The file "+filename+" can't find.")
来一个实际的例子1:
filename = 'old man and sea.txt'#这里的文件是存在的
try