Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79041 > unrolled thread

Re: TypeError: 'kwarg' is an invalid keyword argument for this function

Started byDave Angel <davea@davea.name>
First post2014-10-13 06:04 -0400
Last post2014-10-14 15:55 +1000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: TypeError: 'kwarg' is an invalid keyword argument for this function Dave Angel <davea@davea.name> - 2014-10-13 06:04 -0400
    Re: TypeError: 'kwarg' is an invalid keyword argument for this function alex23 <wuwei23@gmail.com> - 2014-10-14 15:55 +1000

#79041 — Re: TypeError: 'kwarg' is an invalid keyword argument for this function

FromDave Angel <davea@davea.name>
Date2014-10-13 06:04 -0400
SubjectRe: TypeError: 'kwarg' is an invalid keyword argument for this function
Message-ID<mailman.14817.1413194487.18130.python-list@python.org>
Ian Kelly <ian.g.kelly@gmail.com> Wrote in message:
> On Sun, Oct 12, 2014 at 6:55 AM, roro codeath <rorocodeath@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

[toc] | [next] | [standalone]


#79077

Fromalex23 <wuwei23@gmail.com>
Date2014-10-14 15:55 +1000
Message-ID<m1idru$d5h$1@dont-email.me>
In reply to#79041
On 13/10/2014 8:04 PM, Dave Angel wrote:
> It would also help to spell it the same.  In the OP's
>   implementation,  he defined kwargs, and tried to use it as
>   kwarg.

That's perfectly okay, though: if `kwargs` is the name used to reference 
the dictionary of keyword arguments, `kwarg` would be an instance of a 
keyword argument.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web