【发布时间】:2017-10-06 07:44:11
【问题描述】:
更新
其实我已经测试了所有的答案,但是我想要的一个功能仍然无法实现。使用@property 强制子类直接声明属性,但不能在一个函数中声明self.property = xxx 之类的东西。我怎么也能做到这一点?
我的意思是,如果子类__get__ 是__set__ 之前的属性,那么就提升NotImplementedError。
如何在超类中声明一个变量应该在子类中实现?
也就是说,我想在超类中声明一个虚拟变量。
class A:
def a(self): # perfect!
raise NotImplementedError("...")
b = raise NotImplementedError("...") #how to declare a variable similar with the function above?
【问题讨论】:
标签: python