我正在尝试使用Python在Autodesk Maya(2015)中完成一些装配任务。我遇到了一些我认为很奇怪的事情:
for source, destination in SCENE.Left_BallFoot_orientConstraint.connections(c=1,p=1):
print source, destination
提供以下输出,__str__()
即Attributes的:
Left_BallFoot_orientConstraint.constraintRotateX Left_BallFoot.rotateX
Left_BallFoot_orientConstraint.constraintRotateY Left_BallFoot.rotateY
Left_BallFoot_orientConstraint.constraintRotateZ Left_BallFoot.rotateZ
Left_BallFoot_orientConstraint.constraintRotateOrder Left_BallFoot.rotateOrder
Left_BallFoot_orientConstraint.constraintParentInverseMatrix Left_BallFoot.parentInverseMatrix[0]
Left_BallFoot_orientConstraint.constraintJointOrient Left_BallFoot.jointOrient
Left_BallFoot_orientConstraint.target[0].targetRotate Left_Toe_Control.rotate
Left_BallFoot_orientConstraint.target[0].targetRotateOrder Left_Toe_Control.rotateOrder
Left_BallFoot_orientConstraint.target[0].targetParentMatrix Left_Toe_Control.parentMatrix[0]
Left_BallFoot_orientConstraint.target[0].targetJointOrient Left_Toe_Control.jointOrient
Left_BallFoot_orientConstraint.target[0].targetWeight Left_BallFoot_orientConstraint.Left_ToeControlW0
Left_BallFoot_orientConstraint.Left_ToeControlW0 Left_BallFoot_orientConstraint.target[0].targetWeight
但是在print语句的参数周围加上括号:
for source, destination in SCENE.Left_BallFoot_orientConstraint.connections(c=1,p=1):
print(source, destination)
结果输出是这个,__repr__()
返回值:
(Attribute(u'Left_BallFoot_orientConstraint.constraintRotateX'), Attribute(u'Left_BallFoot.rotateX'))
(Attribute(u'Left_BallFoot_orientConstraint.constraintRotateY'), Attribute(u'Left_BallFoot.rotateY'))
(Attribute(u'Left_BallFoot_orientConstraint.constraintRotateZ'), Attribute(u'Left_BallFoot.rotateZ'))
(Attribute(u'Left_BallFoot_orientConstraint.constraintRotateOrder'), Attribute(u'Left_BallFoot.rotateOrder'))
(Attribute(u'Left_BallFoot_orientConstraint.constraintParentInverseMatrix'), Attribute(u'Left_BallFoot.parentInverseMatrix[0]'))
(Attribute(u'Left_BallFoot_orientConstraint.constraintJointOrient'), Attribute(u'Left_BallFoot.jointOrient'))
(Attribute(u'Left_BallFoot_orientConstraint.target[0].targetRotate'), Attribute(u'Left_Toe_Control.rotate'))
(Attribute(u'Left_BallFoot_orientConstraint.target[0].targetRotateOrder'), Attribute(u'Left_Toe_Control.rotateOrder'))
(Attribute(u'Left_BallFoot_orientConstraint.target[0].targetParentMatrix'), Attribute(u'Left_Toe_Control.parentMatrix[0]'))
(Attribute(u'Left_BallFoot_orientConstraint.target[0].targetJointOrient'), Attribute(u'Left_Toe_Control.jointOrient'))
(Attribute(u'Left_BallFoot_orientConstraint.target[0].targetWeight'), Attribute(u'Left_BallFoot_orientConstraint.Left_ToeControlW0'))
(Attribute(u'Left_BallFoot_orientConstraint.Left_ToeControlW0'), Attribute(u'Left_BallFoot_orientConstraint.target[0].targetWeight'))
即使看起来您正在进行函数调用,也没有。在python 2中,print
是一个关键字。因此,您的第二个示例确实是:
print (source, destination)
也就是说,您正在打印一个元组。因此,您得到的实际上str
是的tuple
,它显示的repr
各部分。
在最新版本的python中,您可以通过使用以下命令在python 2中获取print函数以实现兼容性:
from __future__ import print_function
然后,这将达到您的预期(但您的第一个示例将无效)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句