title: Yield in a recursive function
body: <p>I am trying to do something to all the files under a given path. I don't want to collect all the file names beforehand then do something with them, so I tried this:</p>
  
  <pre><code>import os
  import stat
  
  def explore(p):
    s = ''
    list = os.listdir(p)
    for a in list:
      path = p + '/' + a
      stat_info = os.lstat(path )
      if stat.S_ISDIR(stat_info.st_mode):
       explore(path)
      else:
        yield path
  
  if __name__ == "__main__":
    for x in explore('.'):
      print '--&gt;', x
  </code></pre>
  
  <p>But this code skips over directories when it hits them, instead of yielding their contents. What am I doing wrong?</p>