文章目录 背景解决 背景 有时我们打开一个不存在的文件时,可以捕捉到OSError里的[Errno 2] No such file or directory错误但是如果我们在程序的最后进行了保存文件操作 程序会报错:NameError: name ‘f’ is not defined 解决