【发布时间】:2020-07-15 05:58:23
【问题描述】:
我正在使用 python 库,然后我注意到已经定义了一个特定的基类,并且所有其他类都从它派生。 我的问题是为什么我们在编写库时需要这样的定义和结构
class baseclass(object):
def __init__(self):
raise NotImplementedError("this is an abstract class")
def __enter__(self):
raise NotImplementedError("this is an abstract class")
def __exit__(self, exc_type, exc_value, traceback):
raise NotImplementedError("this is an abstract class")
class Myclass(baseclass):
def __init__(self):
""
def __enter__(self):
""
def __exit__(self, exc_type, exc_value, traceback):
""
def method1(self):
pass
【问题讨论】:
-
这真的取决于情况。这里几乎没有足够的信息来回答,而且可能的假设太多。
标签: python-3.x inheritance abstract-class derived-class