title: How can I traverse a file system with a generator?
body: <p>I'm trying to create a utility class for traversing all the files in a directory, including those within subdirectories and sub-subdirectories. I tried to use a generator because generators are cool; however, I hit a snag.</p>
  
  <pre><code>
  def grab_files(directory):
      for name in os.listdir(directory):
          full_path = os.path.join(directory, name)
          if os.path.isdir(full_path):
              yield grab_files(full_path)
          elif os.path.isfile(full_path):
              yield full_path
          else:
              print('Unidentified name %s. It could be a symbolic link' % full_path)
  </code></pre>
  
  <p>When the generator reaches a directory, it simply yields the memory location of the new generator; it doesn't give me the contents of the directory.</p>
  
  <h3>How can I make the generator yield the contents of the directory instead of a new generator?</h3>
  
  <p>If there's already a simple library function to recursively list all the files in a directory structure, tell me about it. I don't intend to replicate a library function.</p>