New "with ignored(*exceptions)" context manager
This commit is contained in:
1 parent
24573c5ef2
commit
f98b0d7b6f
13 files changed
+51
-73
No files matched your search
@@ -163,3 +163,13 @@ def indent_block(text, indention=' '):
|
||||
text = text[:-1]
|
||||
lines = text.split('\n')
|
||||
return '\n'.join(map(lambda s: indention + s, lines)) + temp
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def ignored(*exceptions):
|
||||
"""Context manager that ignores all of the specified exceptions. This will
|
||||
be in the standard library starting with Python 3.4."""
|
||||
try:
|
||||
yield
|
||||
except exceptions:
|
||||
pass
|
||||
Reference in new issue
Block a user