-1
__str__
関数を継承したクラスで設定する次のコードは、selfと最初の属性の間に "行"がないと失敗します。つまり、行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'を適切に受け入れるように定義することができれば、その愚かな '.set(tb)'呼び出しが必要になります。 – ShadowRanger