[dgplug-users] Need Help in understanding the Error Message

Pabitra Pati pabitrakumarpati at gmail.com
Tue Feb 28 03:00:02 PST 2017

On Tue, Feb 28, 2017 at 3:03 PM, Chaitanya Anil Kukde
<chaitanya.kukde at gmail.com> wrote:
> Hi Pabitra,
> From what I understand, the function total is defined using positional parameters, while 'name="Adi"' refers to usage of keyword arguments which is (as I understand) not allowed and this is the cause of the error.

I guess, you have confusion in positional and keyword argument.
Positional - because, in method definition as well as in invocation,
the name parameter is the first argument.
Keyword - Any argument passed in form of "param=value" is said to be
keyword argument.

In my call
total(name="Adi", *(1, 2, 10) )
name='Adi' is therefore, both positional as well as keyword argument.
The thing that is not allowed is passing positional arguments after
keyword argument.
and since here name is both positional as well as keyword, so that is
not the reason for error.

> Relevant material which might help in understanding the underlying mechanisms [0], [1].

Even though your code was correct, but, I am here interested in
knowing the cause for the error.

> Let me know your thoughts. Interesting question btw :)
> 0. https://docs.python.org/2/tutorial/controlflow.html#keyword-arguments
> 1. http://stackoverflow.com/a/1419159
These links were useful though. But, I didn't get my answer.

> Thanks,
> Chaitanya
> On 02/27/2017 03:07 PM, Pabitra Pati wrote:
>> Hi All,
>> 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="Adi", *(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'?
>> Any help is appreciated.
>> *Thanks,*
>> *Pabitra*
>> _______________________________________________
>> Users mailing list
>> Users at lists.dgplug.org
>> http://lists.dgplug.org/listinfo.cgi/users-dgplug.org

Hi Chaitanya,

Thanks for your reply. Please find my response inline.



More information about the Users mailing list