Created
August 18, 2019 09:43
-
-
Save evansde77/a139aaf2ce0b173fe02b9ec3a0ca64b2 to your computer and use it in GitHub Desktop.
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
from contextlib import contextmanager | |
@contextmanager | |
def context1(arg): | |
print("Bronte") | |
yield "Tolkien" | |
print(arg) | |
class Context2: | |
def __init__(self, arg): | |
self.arg = arg | |
print("Austen") | |
def print_arg(self): | |
print(self.arg) | |
def __enter__(self): | |
print("Orwell") | |
return self | |
def __exit__(self, *args): | |
if args: | |
print("Wordsworth") | |
else: | |
print("Conan Doyle") | |
return True | |
with Context2("Dickens") as ctx2: | |
with context1("Kipling") as a: | |
print("Wells") | |
print(a) | |
ctx2.print_arg() | |
raise RuntimeError("Shelley") | |
# What authors get printed in what order? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment