def curry def decorator fn functools wraps fn def surrogate args if le

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
def curry(n):
def decorator(fn):
@functools.wraps(fn)
def surrogate(*args):
if len(args) != n:
raise TypeError("%s() takes exactly %d arguments (%d given)" %
(fn.__name__, n, len(args)))
def curried(*rest, **kws):
return fn(*(args + rest), **kws)
return curried
return surrogate
return decorator
@curry(3)
def spam(a,b,c,d,e,f):
print a,b,c,d,e,f
spam(1,2,3)(4,5,6)