下面用继承类设置__str__
函数的代码将失败,除非self和第一个属性之间有一个“行”,即如果行junk=99,程序炸弹被注释掉
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)
提前感谢你的帮助。在
块(td)设置自我.bidno这是一个模板块。 从那里我怀疑'\n%.2d'%(自我.bidno)引发异常,因为bidno不是数字。在
相关问题 更多 >
编程相关推荐