0

I am trying to accomplish some rigging tasks in Autodesk's Maya (2015) using Python. I have run into something I think is odd:

for source, destination in SCENE.Left_BallFoot_orientConstraint.connections(c=1,p=1):
    print source, destination

Gives the following output, the __str__() of the 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

But with parentheses around the print statement's arguments:

for source, destination in SCENE.Left_BallFoot_orientConstraint.connections(c=1,p=1):
    print(source, destination)

The resulting output is this, the __repr__() return value:

(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'))
  • 1
    See this for [reference](http://stackoverflow.com/questions/6182964/why-is-parenthesis-in-print-voluntary-in-python-2-7) – James Mertz Aug 08 '14 at 17:18

2 Answers2

3

Even though it looks like you're making a function call, you are not. In python 2, print is a keyword. So your 2nd example is really:

print (source, destination)

i.e. you are printing a tuple. So, what you are getting is actually the str of the tuple, which shows the repr of its parts.

In recent versions of python, you can get the print function in python 2 for compatibility, by using

from __future__ import print_function

Then this will do what you expected (but your first example becomes invalid).

FatalError
  • 52,695
  • 14
  • 99
  • 116
  • That makes a lot of sense, I had actually just read about the differences between Python 2 and 3 and how in Python 3, `print` is a function. Thanks for the answer! – aPerfectMisterMan Aug 08 '14 at 17:16
3

In this case here:

print source, destination

You are calling print with two arguments. What print will do is call __str__() on each argument, and display it.

The second case here:

print(source, destination)

is actually interpreted as this:

print (source, destination)

It is converting it to a tuple, and passing it to print as one argument. In that case it calls __str__() on the tuple, which will call __repr__() on each of its elements.

robbrit
  • 17,560
  • 4
  • 48
  • 68