Python:cached_property缓存对象的属性

绪风

关注

阅读 82

2022-02-18


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
"""



精彩评论(0)

0 0 举报