我开始掌握“哎哟”的窍门了。有人能用python上下文向我解释一下这个概念吗?我有几节课:
class A(object):
def __init__(self):
self.foo = 'hello'
class B(A):
def __init__(self):
self.bar = 'world'
我想用它自己的init创建一个类B的实例,但我也希望它有a的init。到目前为止,我所知道的唯一能得到我想要的结果的方法就是在B的基础上复制A的init的代码。
所以我要:
class A(object):
def __init__(self):
self.foo = 'hello'
class B(A):
def __init__(self):
self.foo = 'hello'
self.bar = 'world'