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

Pabitra Pati pabitrakumarpati at gmail.com
Tue Feb 28 06:50:39 PST 2017


On Tue, Feb 28, 2017 at 6:30 PM, Ankur Gupta <ankur0493 at gmail.com> wrote:
> Hi,
>
> Because "Positional arguments can't come after keyword arguments", The
> *args tuple is always unpacked before any keyword argument.

I would like to know where from you found this ? Any reference to from
where you found, would be helpful.
>
> Python interprets your call in the following order:
>
> (1, 2, 10, name="Adi")
>
> Here, '1' is the positional argument for 'name', and then Python also gets
> a keyword argument for it.
>
> So what we get from this is if you are giving a list of *args to a
function
> call, you cannot have any keyword argument before that. If passing
> arguments through *args, the only way to give keyword arguments is by
using
> **kwargs.
>
>
> On Tue, Feb 28, 2017 at 5:09 PM, Ravindra Lakal <ravindra.lakal at gmail.com>
> wrote:
>
>> This link will help you understand the concept of keyword arguments
>> http://pymbook.readthedocs.io/en/latest/functions.html#keyword-arguments
>>
>> On Feb 27, 2017 3:07 PM, "Pabitra Pati" <pabitrakumarpati at gmail.com>
>> 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
>> >
>> _______________________________________________
>> Users mailing list
>> Users at lists.dgplug.org
>> http://lists.dgplug.org/listinfo.cgi/users-dgplug.org
>>
> _______________________________________________
> Users mailing list
> Users at lists.dgplug.org
> http://lists.dgplug.org/listinfo.cgi/users-dgplug.org

Hey Ankur,

Thanks for the answer. But, I would like to know from where you came to
know the highlighted section? Any reference to the same would be helpful.

So could you please send the link for reference?

-- 
Thanks,
Pabitra


More information about the Users mailing list