Created
March 31, 2017 19:07
-
-
Save phobson/83b992e681efe161dcb3d257921b890c to your computer and use it in GitHub Desktop.
Python decorators
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 numpy | |
def _dedenter(func): | |
""" dedents any string returned by a function. """ | |
@wraps(func) | |
def wrapper(*args, **kwargs): | |
string = func(*args, **kwargs) | |
return dedent(string) | |
return wrapper | |
def seed(func): | |
""" Decorator to seed the RNG before any function. """ | |
@wraps(func) | |
def wrapper(*args, **kwargs): | |
numpy.random.seed(0) | |
return func(*args, **kwargs) | |
return wrapper | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment