小编jos*_*nel的帖子

无法使用抽象方法实例化抽象类

我正在研究一种lib,由于一个奇怪的原因,我有这个错误.

  • 是我的代码.当然@ abc.abstractmethod必须取消注释
  • 是我的测试

抱歉,无法复制并粘贴它

我的基础是下面的代码有效

test.py

import abc
import six

@six.add_metaclass(abc.ABCMeta)
class Base(object):

    @abc.abstractmethod
    def whatever(self,):
        raise NotImplementedError

class SubClass(Base):

    def __init__(self,):

        super(Base, self).__init__()
        self.whatever()

    def whatever(self,):
        print("whatever")
Run Code Online (Sandbox Code Playgroud)

在python shell中

>>> from test import *
>>> s = SubClass()
whatever
Run Code Online (Sandbox Code Playgroud)

为什么我的名册模块我有这个错误

Can't instantiate abstract class Player with abstract methods _Base__json_builder, _Base__xml_builder
Run Code Online (Sandbox Code Playgroud)

提前致谢

python abstract-class abc six

25
推荐指数
1
解决办法
3万
查看次数

标签 统计

abc ×1

abstract-class ×1

python ×1

six ×1