Skip to content

Instantly share code, notes, and snippets.

@psav
Created November 4, 2014 14:49
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 psav/afd089ed1583b85fefef to your computer and use it in GitHub Desktop.
Save psav/afd089ed1583b85fefef to your computer and use it in GitHub Desktop.
class Appliance(object):
def __init__(self, var):
print "inited"
self.var = var
def __enter__(self):
print "entering"
print "the var is {}".format(self.var)
return self
def __exit__(self, *args, **kwargs):
print "exiting"
print "the var is {}".format(self.var)
with Appliance("shoes") as app:
app.var = "houses"
print
"""
pp = Appliance("cars")
print pp.var
pp.var = "cheese"
print pp.var
print app.var
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment