You could also explicitly open it as a file.
try:
with open('test.ini') as f:
config.read_file(f)
except IOError:
raise MyError()
EDIT: Updated for python 3.
You could also explicitly open it as a file.
try:
with open('test.ini') as f:
config.read_file(f)
except IOError:
raise MyError()
EDIT: Updated for python 3.