title: how to access the class variable by string in Python?
body: <p>The codes are like this:</p>
  
  <pre><code>class Test:
      a = 1
      def __init__(self):
          self.b=2
  </code></pre>
  
  <p>When I make an instance of <code>Test</code>, I can access its instance variable <code>b</code> like this(using the string "b"):</p>
  
  <pre><code>test = Test()
  a_string = "b"
  print test.__dict__[a_string]
  </code></pre>
  
  <p>But it doesn't work for <code>a</code> as <code>self.__dict__</code> doesn't contain a key named <code>a</code>. Then how can I access<code>a</code> if I only have a string <code>a</code>?</p>
  
  <p>Thanks!</p>