Skip to content

Instantly share code, notes, and snippets.

@lcary
Last active February 15, 2018 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lcary/8bace3daeaa6865cf2872b87f7f75eb8 to your computer and use it in GitHub Desktop.
Save lcary/8bace3daeaa6865cf2872b87f7f75eb8 to your computer and use it in GitHub Desktop.
Example connection used within a with-statement
class Connection(object):
def __init__(self):
print("__init__ Connection")
def __enter__(self):
print("__enter__ Connection")
def __exit__(self, type, value, traceback):
print("__exit__ Connection")
def __del__(self):
print("__del__ Connection")
with Connection():
print("testing Connection...")
## -- When run with python3 --
__init__ Connection
__enter__ Connection
testing Connection...
__exit__ Connection
__del__ Connection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment