安装
pip install lazyprop
例子1
from lazyprop import lazyprop
class Foo(object):
def __init__(self):
self.load_count = 0
@lazyprop
def lazy(self):
self.load_count += 1
f = Foo()
f.lazy
f.lazy
f.lazy
print(f.load_count)
输出:
1
例子2
from lazyprop import lazyprop
class Foo(object):
def __init__(self):
self.load_count = 0
# @lazyprop
def lazy(self):
self.load_count += 1
f = Foo()
f.lazy
f.lazy
f.lazy
print(f.load_count)
输出:
0