TypeError: new() missing 3 required positional arguments: ‘name’, ‘bases’, and ‘namespace’
百思不得其解,最终在外网搜索到了答案:
ABCMeta元类。它是一个元类,而不是基类。
对于Python 2,这意味着将其分配给该类的__metaclass__属性:
class CVIterator(object):
__metaclass__ = ABCMeta
def __init__(self):
self.n = None # the value of n is obtained in the fit method
在Python 3中,定义类时将使用metaclass=…语法:
class CVIterator(metaclass=ABCMeta):
def __init__(self):
self.n = None # the value of n is obtained in the fit method
从Python 3.4开始,可以将 abc.ABC helper class用作基类:
from abc import ABC
class CVIterator(ABC):
def __init__(self):
self.n = None # the value of n is obtained in the fit method```