Update
Actually, I have tested all the answers, but a feature I want still can't be achieved. Using @property
force the subclass to directly declare the property but not something like self.property = xxx
in one function. How could I also achieve this?
I mean, if the subclass __get__
the property before __set__
, then raise NotImplementedError
.
How to declare a variable in the super class which should be implemented in the subclass?
In other word, I want to declare a virtual variable in super class.
class A:
def a(self): # perfect!
raise NotImplementedError("...")
b = raise NotImplementedError("...") #how to declare a variable similar with the function above?