在Python中,函数的参数是否可以有双重名称?
我的意思是变量名的简短和完整形式。在
我会尽量说清楚的。熟悉Autodesk Maya的每个人都知道
约束的函数。它有一些标志,您可以使用其名称的短格式或长格式:maintainOffset(mo), weight(w), layer(l) and so on..
因此,您可以使用不同的参数名称调用此函数,但结果相同:cmds.parentConstraint(driverObj, drivenObj, maintainOffset=True, weight=1.0,..)
cmds.parentConstraint(driverObj, drivenObj, maintainOffset=True, w=1.0,..)
cmds.parentConstraint(driverObj, drivenObj, mo=True, weight=1.0,..)
cmds.parentConstraint(driverObj, drivenObj, mo=True, w=True,..)
如何在Python中实现这种类型的行为2.7.x?我正在积极使用文档,但仍然找不到答案。在
除此之外,我还为各种类型的约束定义了4个函数:
^{pr2}$
连接列表:cLst = produceConnectionList(tNodesA, tNodesB)
和一些包装器的函数:def batchConnect(type = "parentConstraint", ???):
cLst = produceConnectionList(tNodesA, tNodesB)
if type is "parentConstraint": doParentConstraint(cLst, ???)
if type is "orientConstraint": doOrientConstraint(cLst, ???)
if type is "pointConstraint": doPointConstraint(cLst, ???)
if type is "scaleConstraint": doScaleConstraint(cLst, ???)
但是我不知道如何在这些函数和包装器之间传递值,因为尽管它们有相同数量的参数,但参数的名称和类型稍有不同。在
另外,我想在调用包装器时有机会使用简短和完整的标志名称:batchConnect("pointConstraint", mo=False, offset=(0,0,0), weight=1)
batchConnect("pointConstraint", maintainOffset=False, o=(0,0,0), w=1)
必须这样做。在batchConnect("pointConstraint")
如果没有参数,则必须使用默认值调用doPointConstraint()。在batchConnect()
如果不指定类型和参数,则默认情况下必须使用这些默认值调用doParentConstraint()