在你写下这篇文章之前,并没有问过我能找到的任何地方。检查一个变量是否存在于Python中 - 不适用于自己
我用
if 'self.locList' in locals():
print 'it exists'
检查名单的存在,但它不工作。它从不认为它存在。这一定是因为我使用继承和self.
在其他地方引用它,我不明白发生了什么。
任何人都可以请一些光吗?
下面是完整的代码:
import maya.cmds as cmds
class primWingS():
def __init__(self):
pass
def setupWing(self, *args):
pass
def createLocs(self, list):
for i in range(list):
if 'self.locList' in locals():
print 'it exists'
else:
self.locList = []
loc = cmds.spaceLocator(n = self.lName('dummyLocator' + str(i + 1) + '_LOC'))
self.locList.append(loc)
print self.locList
p = primWingS()
你能检查你的代码的缩进吗?我想我可以告诉它应该如何,但很难说。 – Marius 2013-02-25 02:31:15
为什么不在'__init__'里面创建它,而不是每次都检查? – wim 2013-02-25 02:32:27