title: Use of python getattr/setattr for current function
body: <p>Is it possible to use <code>getattr</code>/<code>setattr</code> to access a variable in a class function?</p>
  
  <p>Example below.  Say I have a class A, that has two methods, <code>func1</code> and <code>func2</code> both
  of which define a variable <code>count</code> of a different type.  Is there a way to use
  <code>getattr</code> in func2 to access the local variable <code>count</code>?</p>
  
  <p>In reality, I have quite
  a few variables in <code>func2</code> (that are also defined differently in <code>func1</code>) that I want
  to loop through using <code>getattr</code> and I'm looking to shorten up my code a bit by using
  a loop through the variable names.  </p>
  
  <pre><code>class A(object):
  
     def __init__(self):
        pass
  
     def func1(self):
          count = {"A": 1, "B":2}
  
     def func2(self):
          count = [1, 2]
          mean = [10, 20]
          for attr in ("count", "mean"):
             xattr = getattr(self, attr)   ! What do I put in here in place of "self"?
             xattr.append(99)
  </code></pre>