Created
November 8, 2021 15:30
-
-
Save scidam/a146ee42d548ce5fc8b198d9c2af4189 to your computer and use it in GitHub Desktop.
My solution to calculator with context manager
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
| class Calculator: | |
| def __init__(self, *excps): | |
| self.exceptions = excps | |
| self.error = '' | |
| def __enter__(self): | |
| return self | |
| def __exit__(self, exc_type, exc_val, traceback): | |
| self.error = exc_val | |
| if exc_type in self.exceptions: | |
| return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment