如果我然后尝试删除重复项,我会收到TypeError ...为什么?
tempList =列表(集(tempList))
这是真正的代码:
# Lists all UI elements
allUI=pm.lsUI()[24:28]
#Main Window Name
win='searchElementsUI'
#Lists for UI Hierachy
allSplitUI=[]
maxLenUI=[]
parentDict={}
#Splits UI Elements
for ui in allUI:
allSplitUI.append(ui.split('|'))
#Max length of UISplit
for ui in allSplitUI:
maxLenUI.append(len(ui))
maxLenUI=max(maxLenUI)
#Adds main Parents to list
tempList=[]
for i in range(maxLenUI):
tempList=[]
for ui in allSplitUI:
try:
tempList.append(ui[i])
except:pass
tempList=list(set(tempList))
parentDict['list%s'%i]=tempList
这里是玛雅的完整追溯:
# Lists all UI elements
allUI=pm.lsUI()
#Main Window Name
win='searchElementsUI'
#Lists for UI Hierachy
allSplitUI=[]
maxLenUI=[]
parentDict={}
#Splits UI Elements
for ui in allUI:
allSplitUI.append(ui.split('|'))
#Max length of UISplit
for ui in allSplitUI:
maxLenUI.append(len(ui))
maxLenUI=max(maxLenUI)
#Adds main Parents to list
tempList=[]
for i in range(maxLenUI):
tempList=[]
for ui in allSplitUI:
try:
tempList.append(ui[i])
except:pass
tempList=list(set(tempList))
parentDict['list%s'%i]=tempList
# Error: 'str' object is not callable
# Traceback (most recent call last):
# File "<maya console>", line 29, in <module>
# TypeError: 'str' object is not callable #
答案 0 :(得分:1)
如上所述,您要么没有发布您的真实代码,要么发生了非常奇怪的事情。
但是,您可以使用以下行替换几乎整个脚本:
import itertools
alluis = set(itertools.chain.from_iterable(ui.split('|') for ui in pm.lsUI()))
这会分裂,展平并使用set
进行统一。
答案 1 :(得分:0)
您可以尝试以下代码:
#Convert to a set
a =set(tempList)
seen = set()
result = []
for item in a:
if item not in seen:
seen.add(item)
result.append(item)