嘿,伙计们,这段代码来自一个视频教程,让我很困惑:
import maya.cmds as mc
def jointHierarchy(topJoint , lastJoint = True):
jointsLists = mc.listRelatives(topJoint , type = 'joint' , ad = True)
jointsLists .append (topJoint)
jointsLists . reversed()
wholeChane = jointsLists [:]
if not lastJoint:
jointsWithoutEnd = [ j for j in jointsLists if mc.listRelatives( j , type = 'joint' ,c =1 )]
这是什么类型的循环
'''
if not lastJoint:
jointsWithoutEnd = [ j for j in jointsLists if mc.listRelatives( j , type = 'joint' ,c =1 )]
'''
我们有这样的结构吗
j for j in jointsLists if mc.listRelatives( j , type = 'joint' ,c =1 )
我试过这段代码,它工作正常
任何帮助这就像:
jointsWithoutEnd=[]
for j in jointsLists:
if mc.listRelatives(j,type='joint',c=1):
jointsWithoutEnd.append(j)
EDIT:正如RobertB所说,这是列表理解:https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions