title: gettattr , "attributes must be string" error in python
body: <p>I am trying to use <code>getattr</code> function in my code using generator</p>
  
  <pre><code>li=[]
  m=[method for method in dir(li) if callable(getattr(li,method))]
  print getattr(li,(str(i) for i in m))
  </code></pre>
  
  <p><strong>Error</strong>:</p>
  
  <pre><code>TypeError: getattr(): attribute name must be string
  </code></pre>
  
  <p>if I am using string coercion on i, then why this error shows up?</p>
  
  <p>Also,if I use the code</p>
  
  <pre><code>li=[]
  m=[method for method in dir(li) if callable(getattr(li,method))]
  for i in range(10):
      print getattr(li,str(m[i]))
  </code></pre>
  
  <p>Then there is no error</p>
  
  <p>I am new to python, forgive me if i am making very elementary mistake, please can someone elaborate on the error. Thanks</p>
  
  <p><strong>Edit</strong>: The same principle works for this code (it is an example from Dive into python). Here,the same thing is done then why there is no error?</p>
  
  <pre><code>def info(object, spacing=10, collapse=1):
      """Print methods and doc strings.
  
      Takes module, class, list, dictionary, or string."""
      methodList = [e for e in dir(object) if callable(getattr(object, e))]
      processFunc = collapse and (lambda s: " ".join(s.split())) or (lambda s: s)
      print "\n".join(["%s %s" %
                       (method.ljust(spacing),
                        processFunc(str(getattr(object, method).__doc__)))
                       for method in methodList])
  </code></pre>