对 GetData1 的调用运行良好并打印:
hello 67 8.3
对 GetData2 的调用失败:
TypeError: __call__() got an unexpected keyword argument 'arg1'
我的代码是
class Memoized(object):
def __init__(self, func):
self.func = func
self.cache = {}
def __call__(self, *args):
print args
with Locker:
try:
return self.cache[args]
except KeyError:
self.cache[args] = value = self.func(*args)
return value
def GetData1(arg1, arg2, arg3) :
print arg1, arg2, arg3
@Memoized
def GetData2(arg1, arg2, arg3) :
print arg1, arg2, arg3
r = { 'arg1' : 'hello', 'arg2': 67, 'arg3' : 8.3 }
GetData1(**r)
GetData2(**r)