TypeError: got multiple values for argument

python, python-3.x

Solution

This happens when a keyword argument is specified that overwrites a positional argument. For example, let's imagine a function that draws a colored box. The function selects the color to be used and delegates the drawing of the box to another function, relaying all extra arguments.

def color_box(color, *args, **kwargs):
    painter.select_color(color)
    painter.draw_box(*args, **kwargs)

Then the call

color_box("blellow", color="green", height=20, width=30)

will fail because two values are assigned to `color`: `"blellow"` as positional and `"green"` as keyword. (`painter.draw_box` is supposed to accept the `height` and `width` arguments).

This is easy to see in the example, but of course if one mixes up the arguments at call, it may not be easy to debug:

# misplaced height and width
color_box(20, 30, color="green")

Here, `color` is assigned `20`, then `args=[30]` and `color` is again assigned `"green"`.

Problem

I have this code: ``` BOX_LENGTH = 100 turtle.speed(0) fill = 0 for i in range(8): fill += 1 if fill % 2 == 0: Horizontol_drawbox(BOX_LENGTH, fillBox = False) else: Horizontol_drawbox(BOX_LENGTH, fillBox = True) for i in range(8): fill += 1 if fill % 2 == 0: Vertical_drawbox(BOX_LENGTH,fillBox = False) else: Vertical_drawbox(BOX_LENGTH,fillBox = True) ``` But I get an error that says: ``` Horizontol_drawbox(BOX_LENGTH, fillBox = True) TypeError: Horizontol_drawbox() got multiple values for argument 'fillBox' ``` What does this mean, and how can I fix the problem?

Original source

Related problems