是的你可以。使用@property
装饰器。例如,如果您有一个名为“example”的字段,那么您将无法执行以下操作:
class Base(object):
@property
def example(self):
raise NotImplementedError("Subclasses should implement this!")
运行以下命令将产生NotImplementedError
您想要的结果。
b = Base()
print b.example