TypeError: 'kwarg' is an invalid keyword argument for this function
Ian Kelly
ian.g.kelly at gmail.com
Sun Oct 12 14:45:14 EDT 2014
More information about the Python-list mailing list
Sun Oct 12 14:45:14 EDT 2014
- Previous message (by thread): TypeError: 'kwarg' is an invalid keyword argument for this function
- Next message (by thread): TypeError: 'kwarg' is an invalid keyword argument for this function
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sun, Oct 12, 2014 at 6:55 AM, roro codeath <rorocodeath at 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'
- Previous message (by thread): TypeError: 'kwarg' is an invalid keyword argument for this function
- Next message (by thread): TypeError: 'kwarg' is an invalid keyword argument for this function
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list