title: How do I check if a static variable exists in Python?
body: <p>This is a related question: <a href="https://stackoverflow.com/questions/843277/how-do-i-check-if-a-variable-exists-in-python">How do I check if a variable exists?</a></p>
  
  <p>However, it did not work well for static variables.</p>
  
  <p>What I am trying to do is the following,</p>
  
  <pre><code>class A:
      def __init__(self):
          if A.var is null: # this does not work, okay
              A.var = 'foo'
              print 'assigned'
  </code></pre>
  
  <p>Okay, since <code>A.var</code> is not even assigned. It raises en error. So, I tried this:</p>
  
  <pre><code>class A:
      def __init__(self):
          if 'A.var' not in globals(): # this seems to okay, but ..
              A.var = 'foo'
              print 'assigned'
  
  a = A()
  b = A()
  </code></pre>
  
  <p>It results:</p>
  
  <pre><code>assigned
  assigned
  </code></pre>
  
  <p>Which shows that <code>if 'A.var' not in globals():</code> line not working properly.</p>
  
  <p>So, how do I check if a static variable exists in Python?</p>