cached_property

#firstly

pip install cached_property

#and then:

 

from cached_property import cached_property


class A(object):
    def __init__(self):
        self.value = 0

    # @cached_property
    # def new_value(self):
    #     self.value += 10
    #     return self.value

    @property
    def new_value(self):
        self.value += 10
        return self.value

a = A()

print a.new_value
print a.new_value
print a.new_value
print a.new_value


#you can see the differences between them .

  

原文地址:https://www.cnblogs.com/575dsj/p/8213698.html