Skip to content

Instantly share code, notes, and snippets.

@im-n1
Created September 3, 2018 19:43
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save im-n1/8a606fb5cedf59e8966ca4489976582d to your computer and use it in GitHub Desktop.
from contextlib import contextmanager
class X(object):
@contextmanager
def y(self):
print("before")
x = 1
yield x
print("after")
x = X()
with x.y() as variable:
print(variable)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment