我的代碼複製 'memoize的' 功能:爲什麼我的代碼錯誤?我在django.utils.functional
a=[1,2,3,4]
b=a[:2]
c=[]
c[b]='sss'#error
memoize的功能:
def memoize(func, cache, num_args):
def wrapper(*args):
mem_args = args[:num_args]#<------this
if mem_args in cache:
return cache[mem_args]
result = func(*args)
cache[mem_args] = result#<-----and this
return result
爲什麼你要複製這個函數呢?它應該工作得很好。只需導入它,然後使用它。 'from django.utils.functional import memoize; memoize的(富)'。 – jcdyer 2010-01-06 12:47:49