Шаг 1 из 4+110 XP
Менеджеры контекста
__enter__/__exit__ или contextlib.contextmanager.
with
from contextlib import contextmanager
@contextmanager
def tag(name):
print(f"<{name}>")
yield
print(f"</{name}>")
with tag("p"):
print("hi")__enter__/__exit__ или contextlib.contextmanager.
from contextlib import contextmanager
@contextmanager
def tag(name):
print(f"<{name}>")
yield
print(f"</{name}>")
with tag("p"):
print("hi")