Skip to content

Instantly share code, notes, and snippets.

@Dunes
Last active October 21, 2015 04:39
Show Gist options
  • Save Dunes/da9ad871b91f6f3b0f55 to your computer and use it in GitHub Desktop.
Save Dunes/da9ad871b91f6f3b0f55 to your computer and use it in GitHub Desktop.
class MyContextManager:
def __enter__(self):
return self
def __exit__(self, type_, value, traceback):
# marks exception as being handled, and so it is not re-raised outside of the with block
return True
with MyContextManager():
raise ValueError
data = None
print(data) # raises NameError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment