[英]How to list all class cached_properties in Python?
這是一個例子:
import statistics
from functools import cached_property
class DataSet:
def __init__(self, sequence_of_numbers):
self._data = sequence_of_numbers
@cached_property
def stdev(self):
return statistics.stdev(self._data)
@cached_property
def variance(self):
return statistics.variance(self._data)
列出緩存屬性的最簡單方法是什么?
我有一個解決方案:
import inspect
import functools
list_of_cached_properties_names = [
name for name, value in inspect.getmembers(DataSet)
if isinstance(value, functools.cached_property)
]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.