我有一个名为cached_classproperty()
的函数
该函数使缓存描述符可以通过类访问。
def cached_classproperty(timeout=None):
class Inner(object):
def __init__(self, function):
self.function = function
def __get__(self, inst, cls):
if cache_key not in cache:
cache[cache_key] = self.function(cls)
return cache[cache_key]
return Inner
该功能需要前缀cached_
。
如何将功能cached_classproperty()
命名为更短更清洁?
答案 0 :(得分:1)
您可以将函数引用分配给变量,如:
a = cached_classproperty
然后称之为:
a()