我在模块中有以下装饰器:
class CachedProperty(object):
"""Decorator that lazy-loads the value of a property.
The first time the property is accessed, the original property function is
executed. The value it returns is set as the new value of that instance's
property, replacing the original method.
"""
def __init__(self, wrapped):
self.wrapped = wrapped
try:
self.__doc__ = wrapped.__doc__
except:
pass
def __get__(self, instance, instance_type=None):
if instance is None:
return self
value = self.wrapped(instance)
setattr(instance, self.wrapped.__name__, value)
return value
我想从模块中导入这个装饰器和其他东西,如下所示:
from clang.cindex import *
但是我无法以这种方式导入那个单一的装饰器,如果我这样做,它就可以工作:
from clang.cindex import CachedProperty
然后我可以使用@CachedProperty
.
为什么我不能导入这个类,*
而我可以导入其他类?