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
Not an answer, a follow up question (since I can't add a comment without 50 reputation), could you please elaborate or use simple terms as the answers here are above my comprehension. I have a similar issue using a button in Maya
import maya.cmds as cmds
from functools import partial
class Myclass(object):
def __init__(self):
pass
def createui(self):
derp = cmds.window()
cmds.formLayout()
cmds.button(label = "w/e", c = partial(self.f, x = 3))
cmds.showWindow(derp)
def f(self, x = 5, y = 3, *_):
print(x+y)
herp = Myclass()
herp.createui()
clicking on the button will give that same error "got multiple values for keyword argument 'x'"
even though what I thought was being sent as arguments was a call to the class, some stupid call to the UI element itself (usually a value of False) which should be put in the *_ catch all argument, and then keyword argument of x.