I want to memoize the result of a function in a class:
class memoize:
def __init__(self, function):
self.function = function
self.memoized = {}
def __call__(self, *args):
try:
return self.memoized[args]
except KeyError, e:
self.memoized[args] = self.function(*args)
return self.memoized[args]
class DataExportHandler(Object):
...
@memoize
def get_province_id(self, location):
return search_util.search_loc(location)[:2] + '00000000'
def write_sch_score(self):
...
province_id = self.get_province_id(location)
but this doesn't work, because it tells me that get_province_id takes exactly 2 arguments(1 given)