如何声明必须使用abcmeta
定义抽象类变量。
例如
class AbstractMover(metaclass=ABCMeta):
_destination_folder = NotImplementedError # how do I do something like this
@property
def destination_folder(self):
return self._destination_folder
,并且在继承时,如果未指定_destination_folder
,则会引发错误。
class ConcreteMover(AbstractMover): pass # should error
class ConcreteMover(AbstractMover):
_destination_folder = "path/to/folder" # works fine
这应该让我做
>>> ConcreteMover().destination_folder
path/to/folder
但是如果未在具体类中定义_destination_folder
,则会引发错误。