小编pen*_*ute的帖子

清除@property方法python的缓存

我在一个类中有一些属性方法,我想在某个时候清除此属性的缓存。

范例:

class Test():
    def __init__(self):
        pass

    @property
    @functools.lru_cache()
    def prop(self):
        # Compute some stuffs and return complex number
Run Code Online (Sandbox Code Playgroud)

如果我做self.prop.clear_cache(),在这里我得到以下错误信息:

AttributeError: 'numpy.complex128' object has no attribute 'cache_clear'
Run Code Online (Sandbox Code Playgroud)

clear_cache()适用于函数,但不适用于属性方法。有什么办法吗?

python python-3.x

2
推荐指数
1
解决办法
201
查看次数

标签 统计

python ×1

python-3.x ×1