title: Does Python allow a recursive __iter__ function?
body: <p>I'm trying to write an <code>__iter__</code> function that should traverse a directory recursively (including subdirectories), and since its structure is arbitrary, I thought a recursive function would be the way to go. But it isn't working.</p>
  
  <p>Here's what I have:</p>
  
  <pre><code>class Dummy(object):
  
      def __init__(self, directory):
          self.directory = directory
  
      def _iterate_on_dir(self, path):
          '''
          Internal helper recursive function.
          '''
          for filename in os.listdir(path):
              full_path = os.path.join(path, filename)
              if os.path.isdir(full_path):
                  self._iterate_on_dir(full_path)
              else:
                  yield full_path
  
      def __iter__(self):
          '''
          Yield filenames
          '''
          return self._iterate_on_dir(self.directory)
  </code></pre>
  
  <p>Some <code>print</code> statements showed me that the recursive call is simply ignored. </p>
  
  <p>How can I accomplish this?</p>