Skip to content

Instantly share code, notes, and snippets.

@phobson
Created March 31, 2017 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phobson/83b992e681efe161dcb3d257921b890c to your computer and use it in GitHub Desktop.
Save phobson/83b992e681efe161dcb3d257921b890c to your computer and use it in GitHub Desktop.
Python decorators
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