Inheriting from str

2021-09-20 Thread ast
Hello class NewStr(str): def __init__(self, s): self.l = len(s) Normaly str is an immutable type so it can't be modified after creation with __new__ But the previous code is working well obj = NewStr("qwerty") obj.l 6 I don't understand why it's working ? (python 3.9) -- https:/

Re: Inheriting from str

2021-09-20 Thread Jon Ribbens via Python-list
On 2021-09-20, ast wrote: > Hello > > class NewStr(str): > def __init__(self, s): > self.l = len(s) > > Normaly str is an immutable type so it can't be modified > after creation with __new__ > > But the previous code is working well > > obj = NewStr("qwerty") > obj.l > 6 > > I don't und

Re: Problem Inheriting from "str" Class

2007-06-12 Thread Gabriel Genellina
En Wed, 13 Jun 2007 03:01:16 -0300, [EMAIL PROTECTED] <[EMAIL PROTECTED]> escribió: > I'm writing a program and want to create a class that is derived from > the "str" base type. When I do so, however, I have problems with the > __init__ method. When I run the code below, it will call my new >

Problem Inheriting from "str" Class

2007-06-12 Thread [EMAIL PROTECTED]
I'm writing a program and want to create a class that is derived from the "str" base type. When I do so, however, I have problems with the __init__ method. When I run the code below, it will call my new __init__ method when there is zero or one (value) parameter. However, if I try to pass two pa