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

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