First I quote the answer of Jack o'Connor from this thread. The referenced thread got closed so I write here:
"There's a new way to do this coming in Python 3.4:
from contextlib import suppress
with suppress(Exception):
# your code
Here's the commit that added it: http://hg.python.org/cpython/rev/406b47c64480
And here's the author, Raymond Hettinger, talking about this and all sorts of other Python hotness: https://youtu.be/OSGv2VnC0go?t=43m23s
My addition to this is the Python 2.7 equivalent:
from contextlib import contextmanager
@contextmanager
def ignored(*exceptions):
try:
yield
except exceptions:
pass
Then you use it like in Python 3.4:
with ignored(Exception):
# your code