title: Python __iter__ and for loops
body: <p>As I understand it, I can use the <code>for</code> loop construction on an object with a <code>__iter__</code> method that returns an iterator.  I have an object for which I implement the following <code>__getattribute__</code> method:</p>
  
  <pre><code>def __getattribute__(self,name):
      if name in ["read","readlines","readline","seek","__iter__","closed","fileno","flush","mode","tell","truncate","write","writelines","xreadlines"]:
          return getattr(self.file,name)
      return object.__getattribute__(self,name)
  </code></pre>
  
  <p>I have an object of this class, <code>a</code> for which the following happens:</p>
  
  <pre><code>&gt;&gt;&gt; hasattr(a,"__iter__")
  True
  &gt;&gt;&gt; for l in a: print l
  ...
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  TypeError: 'TmpFile' object is not iterable
  &gt;&gt;&gt; for l in a.file: print l
  ...
  &gt;&gt;&gt;
  </code></pre>
  
  <p>So python sees that <code>a</code> has an <code>__iter__</code> method, but doesn't think it is iterable.  What have I done wrong?  This is with python 2.6.4.</p>