Skip to main content
 首页 » 编程设计

python之无法从 String 生成输出差异

2025年05月04日9lonelyxmas

首先,如果我的主题标题有误,我深表歉意,因为我不知道如何用更好的方式来表达它。我试图打印出列表中不包含单词 Shape 的项目,但我根本无法获得输出。它生成了一些东西,但它仍然是错误的。

在下面的代码中,我已经写出了输出,但正如您在最后一行中看到的那样,它没有生成 "group1"、"locator1"和 "pCube1",而是生成了 pCubeShape1。

有人可以就此给我建议吗?非常感谢。

import maya.cmds as cmds 
 
newSel01 = cmds.ls(sl=True) 
# [u'group1', u'locator1', u'locatorShape1', u'pCube1', u'pCubeShape1'] 
 
if "Shape" in str(newSel01): 
    if item in newSel01: 
        print item 
        # pCubeShape1 

请您参考如下方法:

据我了解,您想过滤掉列表中不包含单词“Shape”的所有项目:

>>> x = [u'group1', u'locator1', u'locatorShape1', u'pCube1', u'pCubeShape1'] 
>>> filter(lambda s:  "Shape" not in s, x)                                                                                                                                      
[u'group1', u'locator1', u'pCube1']