Olvasd el a kódot figyelmesen
from contextlib import contextmanager
@contextmanager
def track(label):
print(f"enter:{label}")
try:
yield label.upper()
except ValueError as e:
print(f"caught:{e}")
finally:
print(f"exit:{label}")
with track("a") as t:
print(f"body:{t}")
with track("b") as t:
print(f"body:{t}")
raise ValueError("oops")
print("done")
Mit ír ki a program? Írd ide: