Python2.7 处理FileNotFoundError异常

读取不存在的文件alice.txt

#!/usr/bin/env python

-*- coding: utf-8 -*-

filename='alice.txt'
try:
with open(filename) as file_object:
contents=file_object.read()
except FileNotFoundError:
message="Sorry,the file "+filename+" does not exist."
print(message)

图片说明
请问各位大神这是什么情况~

用IOError替换FileNotFoundError,
另外,查看文件是否存在可以用
import os.path
os.path.isfile(fname)