Advertisement
Guest User

Untitled

a guest
Sep 24th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. class sx:
  2.     def __init__(self, vl):
  3.         self.vv = vl
  4.  
  5.     def __enter__(self):
  6.         try:
  7.             print("in enter")
  8.             sleep(100)
  9.             print(2+self.vv)
  10.  
  11.         except (Exception, KeyboardInterrupt) as exc:   # WHEN this line is `except Exception as exc`, then it does not catch KeyboardInterrupt. Why? - KeyboardInterrupt is not an exception? :S
  12.             print("innner exception")
  13.             self.__exit__(exc)
  14.  
  15.     def __exit__(self, exc, *args):
  16.         print("exiting")
  17.  
  18. with sx('a'):
  19.     print(2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement