0
点赞
收藏
分享

微信扫一扫

Python:cached_property缓存对象的属性

绪风 2022-02-18 阅读 72


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 条评论