title: Checking if a Variable Exists in Python - Doesn't work with self
body: <p>Before you down rep this post, it hasn't been asked anywhere that I can find.</p>
  
  <p>I'm checking for the existence of a list by using </p>
  
  <pre><code>if 'self.locList' in locals():
      print 'it exists'
  </code></pre>
  
  <p>But it doesn't work. It never thinks it exists. This must be because I'm using inheritance and the <code>self.</code> to reference it elsewhere, I don't understand what's happening.</p>
  
  <p>Can anyone shed some light please?</p>
  
  <p>Here is the full code:</p>
  
  <pre><code>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()
  </code></pre>