Ian Kelly <ian.g.ke...@gmail.com> Wrote in message:
> On Sun, Oct 12, 2014 at 6:55 AM, roro codeath <rorocode...@gmail.com> wrote:
>> How to implement it in my class?
>>
>> class Str(str):
>>     def __init__(self, *args, **kwargs):
>>         pass
>>
>> Str('smth', kwarg='a')
> 
> The error is coming from the __new__ method. Because str is an
> immutable type, you should override the __new__ method, not __init__.
> Example:
> 
> class Str(str):
>     def __new__(cls, *args, **kwargs):
>         return super().__new__(cls, args[0])
> 
>>>> Str('smth', kwarg='a')
> 'smth'
> 

It would also help to spell it the same.  In the OP's
 implementation,  he defined kwargs, and tried to use it as
 kwarg.


-- 
DaveA

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to