我阅读了与此错误有关的其他线程,似乎我的问题与我到目前为止阅读的所有帖子有一个有趣的明显区别,即,到目前为止所有其他帖子都有关于用户创建的错误类或内置系统资源。我在调用函数时遇到了这个问题,我无法弄清楚它的用途。有任何想法吗?
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)
错误信息:
Horizontol_drawbox(BOX_LENGTH, fillBox = True)
TypeError: Horizontol_drawbox() got multiple values for argument 'fillBox'
原文由 chopper draw lion4 发布,翻译遵循 CC BY-SA 4.0 许可协议
当指定的关键字参数覆盖了位置参数时,就会发生这种情况。例如,让我们想象一个绘制彩色框的函数。该函数选择要使用的颜色并将框的绘制委托给另一个函数,传递所有额外参数。
然后打电话
将失败,因为两个值被分配给
color
:"blellow"
作为位置和"green"
作为关键字。 (painter.draw_box
应该接受height
和width
参数)。这在示例中很容易看出,但当然,如果在调用时混淆了参数,则可能不容易调试:
Here,
color
is assigned20
, thenargs=[30]
andcolor
is again assigned"green"
.