发布时间:2019-09-21 10:44:57编辑:auto阅读(3250)
class Memoize(object):
    def __init__(self, func):
        self.func = func
        # self.cache = {(ADMIN_USER, ADMIN_PASSWORD): ADMIN_USER, }
        self.cache = {}
    def __call__(self, *args):
        print 'args: ', args
        print 'cache: ', self.cache
        try:
            return self.cache[args]
        except KeyError:
            value = self.func(*args)
            self.cache[args] = value
            return value
        except TypeError:
            return self.func(*args)
    def __repr__(self):
        return self.func.__doc__ or ''
    def __get__(self, obj, objtype):
        """
        Support instance methods. Important
        :param obj:
        :param objtype:
        :return:
        """
        print "obj : ", obj
        print "objtype : ", objtype
        return functools.partial(self.__call__, obj)
    def __str__(self):
        return str(self.func)
上一篇: Python string compar
下一篇: python读取pdf文档-实战
 51195
 50611
 41234
 38052
 32514
 29421
 28282
 23137
 23095
 21433
 1490°
 2203°
 1826°
 1754°
 2065°
 1815°
 2500°
 4195°
 4056°
 2896°