-1

如果我然后尝试删除重复项,我会收到 TypeError ......为什么?

临时列表=列表(设置(临时列表))

错误:TypeError:文件第 29 行:“str”对象不可调用#

这是真正的代码:

# 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

这是来自 Maya 的完整回溯:

# 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 # 
4

2 回答 2

1

如前所述,您要么没有发布您的真实代码,要么正在发生一些非常奇怪的事情。

但是,您几乎可以用以下行替换整个脚本:

import itertools
alluis = set(itertools.chain.from_iterable(ui.split('|') for ui in pm.lsUI()))

这会分裂、变平并用于唯一化set

于 2013-07-20T22:51:01.803 回答
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)
于 2013-07-20T21:01:14.867 回答