【发布时间】:2017-08-01 05:47:36
【问题描述】:
我正在尝试为子类创建类方法构造函数,但无法正确初始化实例。
我已经阅读了该网站上的许多博客和答案,甚至尝试了其他人发布的内容,但仍然无济于事。希望我错过了一些非常简单的东西。我正在尝试的基本示例:
class A(object):
def __init__(self, foo):
self.foo = foo
class B(A):
@classmethod
def make_new(cls):
super(B, cls).__init__('bar')
foobar = B.make_new()
我不断收到未绑定方法错误:
TypeError: unbound method __init__() must be called with B instance as first argument (got str instance instead)
【问题讨论】:
-
很高兴您在遇到新问题后接受了我提出的新问题的建议。我知道你会做到的;),对于这个问题是一个加分项,如果我不能及时回答,对不起
标签: python-2.7 constructor superclass class-method