[Tutor] Understanding the error "method got multiple values for keyword argument "
Pabitra Pati
pabitrakumarpati at gmail.com
Wed Mar 1 03:18:04 EST 2017
I want to understand the error message I am getting.
Below is my code piece :-
def total(name, *args):
if args:
print("%s has total money of Rs %d/- " %(name, sum(args)))
else:
print("%s's piggy bank has no money" %name)
I can call this method passing the extra arguments inside *().
*I know the correct way of passing the arguments.* But, I am passing value
for 'name' in form of param=value, *intentionally*, so that it throws me
error. However, I am unable to understand the below error message :-
>>> total(name="John", *(1, 2, 10) )
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: total() got multiple values for keyword argument 'name'
How Python is evaluating the above call, that it's getting multiple values
for the parameter 'name'? How the call is being interpreted internally?
Any insight to the same would be appreciated.
--
*Thanks,*
*Pabitra*
More information about the Tutor
mailing list