您当前的位置: 首页 >  Python

彭世瑜

暂无认证

  • 1浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Python:cached_property缓存对象的属性

彭世瑜 发布时间:2021-02-05 10:17:40 ,浏览量:1

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
"""
关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.3293s