[dgplug-users] Need Help in understanding the Error Message
ankur0493 at gmail.com
Tue Feb 28 05:00:03 PST 2017
Because "Positional arguments can't come after keyword arguments", The
*args tuple is always unpacked before any keyword argument.
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
On Tue, Feb 28, 2017 at 5:09 PM, Ravindra Lakal <ravindra.lakal at gmail.com>
> This link will help you understand the concept of keyword arguments
> On Feb 27, 2017 3:07 PM, "Pabitra Pati" <pabitrakumarpati at gmail.com>
> > 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
> > 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
More information about the Users