Skip to content

Instantly share code, notes, and snippets.

@goyalrohit
Created February 1, 2018 10:16
Show Gist options
  • Save goyalrohit/0268b66a1fcd02573ba4eccc5cddcfd7 to your computer and use it in GitHub Desktop.
Save goyalrohit/0268b66a1fcd02573ba4eccc5cddcfd7 to your computer and use it in GitHub Desktop.
class LoggingContextManager:
def __enter__(self):
print('LoggingContextManager.__enter__()')
return "You are in a with block"
def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type is None:
print('LoggingContextManager.__exit__:'
'normal exit detected.')
else:
print('LoggingContextManager.__exit__:'
'Exception Detected'
'type={}, value={}, traceback={}'.format(exc_type, exc_val, exc_tb))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment