examples/files/open_file.py
#!/usr/bin/env python

filename = 'examples/files/unicorns.txt'

f = open(filename, 'r')

# Traceback (most recent call last):
#   File "examples/files/open_file.py", line 5, in <module>
#     f = open(filename, 'r')
# IOError: [Errno 2] No such file or directory: 'examples/files/unicorns.txt'

Exception handling

examples/files/open_file_handle.py
#!/usr/bin/env python
from __future__ import print_function

filename = 'examples/files/unicorns.txt'

try:
    f = open(filename, 'r')
except IOError:
    print('There was some error opening the file')

print('Still running')