1
如何重載類方法? 我失敗:Python類方法重載
class D(object):
def create(self):
foo = 100
bar = 'squirrels'
baz = 'I have %d insane %s in my head.' % (foo, bar)
return baz
class C(D):
def create(self):
super(C, self).create()
baz = 'I have %s cute %s in my yard.' % (self.foo, self.bar)
C().create()
回溯是:
AttributeError: 'C' object has no attribute 'foo'
'create()'不返回'D'和' 'C'對象,但是一個字符串。所以'__init__'可能不會導致某處... – glglgl
@glglgl你是對的,回答編輯。 –