Github: https://github.com/pydanny/cached-property
Pypi:https://pypi.org/project/cached-property/
安装
pip install cached-property
示例
# -*- coding: utf-8 -*-
from cached_property import cached_property
class Foo(object):
@cached_property
def foo(self):
print("cached_property")
return 'foo'
foo = Foo()
print(foo.foo)
print(foo.foo)
"""
cached_property
foo
foo
"""