欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

马哥 今日小技巧 Python3.8的functools中新增了叫cached_property的装饰器 有大用

Python3.8的functools中新增了叫cached_property的装饰器,看名字应该大概知道什么作用了,看以下例子:

from functors import cached_property

class A:

@cached_property

def say(self):

print(‘****’)

return ‘hello’


a = A()

a.say

以上例子只有第一次访问say属性时才会打印****


普通分类: