使用'expect'方法捕获Python异常?

1 python

import sys
try:
        file = open("words.txt")
expect(IOError):

if file:
    print "%s" % file
else:
    print "Cant the %s file" % "words.txt"
Run Code Online (Sandbox Code Playgroud)

这给了我一个错误 -

File "main.py", line 4 
    expect(IOError):
    SyntaxError: invaild syntax
Run Code Online (Sandbox Code Playgroud)

我出了什么问题/你如何解决这个问题

rog*_*pvl 12

实际上,除了例外情况外:

例如:

except IOError:
    print "Error opening file!"
Run Code Online (Sandbox Code Playgroud)