我正试图在座标上写一个治愈器。 我是:
def curry(fun):
cache = []
numargs = fun.func_code.co_argcount
def new_fun(*args, **kwargs):
print(args)
print(kwargs)
cache.extend(list(args))
if len(cache) >= numargs: # easier to do it explicitly than with exceptions
temp = []
for _ in xrange(numargs):
temp.append(cache.pop())
fun(*temp)
return new_fun
@curry
def myfun(a,b):
print(a,b)
在以下案件中,这部法律课以罚款:
myfun(5)
myfun(5)
对于以下案件,它未能做到:
myfun(6)(7)
我如何能够正确这样做?
If you re just looking to bind arguments to a function and aren t interested in a specific design or the underlying computer science principles, see Python Argument Binders.