inheritance from str or int

Posted by wiso on Stack Overflow See other posts from Stack Overflow or by wiso
Published on 2010-04-20T08:31:59Z Indexed on 2010/04/20 8:33 UTC
Read the original article Hit count: 320

Filed under:
|
|
|
|

Why I have problem creating a class the inherite from str (or also int)

class C(str):
   def __init__(self, a, b):
     str.__init__(self,a)
     self.b = b

C("a", "B")

TypeError: str() takes at most 1 argument (2 given)

tha same appened if I try to use int instead of str, but it works with custom classes. I need to use __new__ instead of __init__? why?

© Stack Overflow or respective owner

Related posts about python

Related posts about inheritance