Re: multiple values for keyword argument
- From: Peter Otten <__peter__@xxxxxx>
- Date: Sat, 29 Jan 2011 14:54:08 +0100
Tobias Blass wrote:
On Sat, 29 Jan 2011, Francesco Bochicchio wrote:
On 29 Gen, 12:10, Tobias Blass <tobiasbl...@xxxxxxx> wrote:
Hi all
I'm just learning python and use it to write a GUI (with Tkinter) for a
C program I already wrote. When trying to execute the program below I
get the following error message.
Traceback (most recent call last):
File "./abirechner.py", line 64, in <module>
win =MainWin()
File "./abirechner.py", line 43, in __init__
self.create_edit(row=i);
TypeError: create_edit() got multiple values for keyword argument 'row'
I don't really understand why create_edit gets multiple values, it gets
one Integer after another (as I see it)
Thanks for your help
class MainWin(Frame):
def create_edit(row,self):
Try this:
def create_edit(self, row):
Ok it works now. So the problem was that python requires 'self' to be the
first parameter?
When you invoke a method Python implicitly passes the instance as the first
positional parameter to it, regardless of the name:
.... s = "yadda"class A:
.... def yadda(but_i_dont_want_to_call_it_self):
.... print but_i_dont_want_to_call_it_self.s
....
yaddaA().yadda()
You can provoke the same error with a function:
.... passdef f(a, b):
....
Traceback (most recent call last):f(1, b=2)
f(a=1, b=2)
f(2, a=1)
File "<stdin>", line 1, in <module>
TypeError: f() got multiple values for keyword argument 'a'
You can think of argument binding as a two-step process.
At first positionals are bound to the formal parameters in the order of
appearance from left to right; then named arguments are bound to parameters
with the same name. If a name is already catered by a positional argument
(or a name doesn't occur at all and doesn't have a default value) you get an
Exception.
.
- Follow-Ups:
- Re: multiple values for keyword argument
- From: Tobias Blass
- Re: multiple values for keyword argument
- References:
- multiple values for keyword argument
- From: Tobias Blass
- Re: multiple values for keyword argument
- From: Francesco Bochicchio
- Re: multiple values for keyword argument
- From: Tobias Blass
- multiple values for keyword argument
- Prev by Date: Re: multiple values for keyword argument
- Next by Date: Re: multiple values for keyword argument
- Previous by thread: Re: multiple values for keyword argument
- Next by thread: Re: multiple values for keyword argument
- Index(es):