可能重复:
从 str 或 int 继承
嗨伙计,
我试图继承 int 类但没有任何成功。这是我的尝试:
class SpecialInt(int):
def __init__(self, x, base=10, important_text=''):
int.__init__(self, x, base)
self.important_text=important_text
如果我执行以下操作:
integer = SpecialInt(123, 10, 'rage of the unicorns')
我收到此错误:
TypeRror: int() takes at most 2 arguments (3 given)
有任何想法吗?:)