Python 为什么带括号和不带括号的打印会在

Python 为什么带括号和不带括号的打印会在,python,maya,Python,Maya,我正在尝试使用Python在Autodesk的Maya(2015)中完成一些装配任务。我遇到了一些我认为很奇怪的事情: for source, destination in SCENE.Left_BallFoot_orientConstraint.connections(c=1,p=1): print source, destination 给出以下输出,即属性的\uuu str\uuu(): Left_BallFoot_orientConstraint.constraintRotat

我正在尝试使用Python在Autodesk的Maya(2015)中完成一些装配任务。我遇到了一些我认为很奇怪的事情:

for source, destination in SCENE.Left_BallFoot_orientConstraint.connections(c=1,p=1):
    print source, destination
给出以下输出,即属性的
\uuu str\uuu()

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)
结果输出如下:
\uu repr\uu()
返回值:

(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)
i、 你正在打印一个元组。因此,您得到的实际上是
tuple
str
,它显示了其部分的
repr

在python的最新版本中,您可以使用

from __future__ import print_function

然后,这将实现您期望的功能(但您的第一个示例无效)。

即使看起来您正在进行函数调用,但实际上并非如此。在python 2中,
print
是一个关键字。所以你的第二个例子是:

print (source, destination)
i、 你正在打印一个元组。因此,您得到的实际上是
tuple
str
,它显示了其部分的
repr

在python的最新版本中,您可以使用

from __future__ import print_function
然后,这将实现您预期的效果(但您的第一个示例无效)。

在本例中:

print source, destination
print(source, destination)
您正在使用两个参数调用
print
print
将对每个参数调用
\uuu str\uuuu()
,并显示它

第二种情况是:

print source, destination
print(source, destination)
实际上被解释为:

print (source, destination)
它将其转换为元组,并将其作为一个参数传递给
print
。在这种情况下,它在元组上调用
\uuuuu str\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu

print source, destination
print(source, destination)
您正在使用两个参数调用
print
print
将对每个参数调用
\uuu str\uuuu()
,并显示它

第二种情况是:

print source, destination
print(source, destination)
实际上被解释为:

print (source, destination)

它将其转换为元组,并将其作为一个参数传递给
print
。在这种情况下,它在元组上调用
\uu str\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu()
,元组将在它的每个元素上调用
\uuuuuuuuuuu repr\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu。谢谢你的回答!这很有意义,我实际上刚刚读到了Python2和Python3之间的区别,以及在Python3中,
print
是一个函数。谢谢你的回答!看这个看这个我也投票给你了robbrit。不过法塔莱罗的速度快了一点,所以他得到了绿色的记号。谢谢你的回答!我也投了你一票,robbrit。不过法塔莱罗的速度快了一点,所以他得到了绿色的记号。谢谢你的回答!