NameError: name 'FileNotFoundError' is not defined

可能是python版本的问题

详情参见如下

#py2.7
filename='waiwai.txt'
try:
    with open(filename) as f_obj:
        contents=f_obj.read()
except FileNotFoundError:
    print "Sorry,the file does't exist."

#py3.7
filename='waiwai.txt'
try:
    with open(filename) as f_obj:
        contents=f_obj.read()
except IOError:
    print "Sorry,the file does't exist."

发布了91 篇原创文章 · 获赞 47 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/qq_30007885/article/details/102496366