Advertisement
nux95

limit decorator

May 7th, 2011
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. """
  2. Limits the returnvalue to the given minimum and maxmimum values.
  3. """
  4.  
  5. def limit(min,max):
  6.     def wrapper(f):
  7.         def nf(*args,**kwargs):
  8.             r = f(*args,**kwargs)
  9.             if r < min: return min
  10.             if r > max: return max
  11.             return r
  12.         nf.__name__ = f.__name__
  13.         return nf
  14.     return wrapper
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement