-1
以下用於設置__str__
函數和繼承類的代碼失敗,除非在自我和第一個屬性之間存在「行」,即如果行junk = 99,則被程序炸彈註釋掉python __str__繼承類
class TemplateBlock(object) :
def __init__(self,
tidno = 1):
self.tidno = tidno
def __str__(self) :
return '%.2d:' % (self.tidno)
class Block(TemplateBlock) :
def __init__(self,
junk = 99,
bidno = 3) :
TemplateBlock.__init__(self)
#self.junk = junk
self.bidno = bidno
def __str__(self) :
return TemplateBlock.__str__(self) + '\n%.2d' %(self.bidno)
def set(self,t) :
self.tidno = t.tidno
tb = TemplateBlock(tidno=2)
b = Block(tb)
b.set(tb)
print(b)
感謝您提前尋求幫助。
你能在你的問題中包含回溯嗎?說炸彈不夠描述。 –
炸彈的含義?請提供您看到的例外和追溯。 – ShadowRanger
附註:你將'tb'傳遞給'Block',這沒有意義;它變成了'junk'或'bidno'參數,它們都不應該是'TemplateBlock'。並且你的超類初始化方法調用不會傳遞'tidno'的值,當你可以定義子類接受並恰當地傳遞'tidno'時,'tidno'需要這個愚蠢的'.set(tb)'調用。 – ShadowRanger