Skip to content

Instantly share code, notes, and snippets.

@scidam
Created November 8, 2021 15:30
Show Gist options
  • Select an option

  • Save scidam/a146ee42d548ce5fc8b198d9c2af4189 to your computer and use it in GitHub Desktop.

Select an option

Save scidam/a146ee42d548ce5fc8b198d9c2af4189 to your computer and use it in GitHub Desktop.
My solution to calculator with context manager
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