So I am trying to understand partial
:
import functools
def f(x,y) :
print x+y
g0 = functools.partial( f, 3 )
g0(1)
4 # Works as expected
In:
g1 = functools.partial( f, y=3 )
g1(1)
4 # Works as expected
In:
g2 = functools.partial( f, x=3 )
g2(1)
TypeError: f() got multiple values for keyword argument 'x'
The TypeError
disappears if I use y
as a keyword argument:
In:
g2( y=1 )
4
What causes the TypeError
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…