with_break.py 254 B

1234567891011121314
  1. class CtxMgr:
  2. def __enter__(self):
  3. print("__enter__")
  4. return self
  5. def __exit__(self, a, b, c):
  6. print("__exit__", repr(a), repr(b))
  7. for i in range(5):
  8. print(i)
  9. with CtxMgr():
  10. if i == 3:
  11. break