Created
December 11, 2019 15:07
-
-
Save wood-push-melon/4379cb9b4939d34c82df0543964e1692 to your computer and use it in GitHub Desktop.
Object that Supports with Statement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Connection: | |
def __init__(self): | |
... | |
def __enter__(self): | |
... | |
def __exit__(self, type, value, traceback): | |
... | |
with Connnection as conn: | |
... | |
from contextlib import contextmanager | |
@contextmanager | |
def tag(name): | |
print(f'<{name}>') | |
yield | |
print(f'') | |
with tag('h1'): | |
print('This is the title.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment