Created
November 7, 2017 21:02
-
-
Save sepulchered/d06ea509b271daae85cdea3980c3d917 to your computer and use it in GitHub Desktop.
This file contains 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
import functools | |
def maybe(fn): | |
@functools.wraps(fn) | |
def wrapper(*args, **kwargs): | |
try: | |
return fn(*args, **kwargs) | |
except Exception: | |
return None | |
return wrapper | |
@maybe | |
def divide(num, den): | |
return num / den | |
print(divide(1, 2)) | |
print(divide(1, 0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment