可能是重复问题:
从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')
I get this error:
TypeRror: int() takes at most 2 arguments (3 given)
有什么想法吗? :)