title: Correct usage of os.path and os.join
body: <p>I'm trying to write a handler that acts on files within various subdirectories, but while my script can <em>see</em> these files, it cannot do anything with them because it fails to assemble their paths.</p>
  
  <p>The problematic part comes from this loop:</p>
  
  <pre><code>for (path, dirs, files) in os.walk("data/"):
      for image in files: 
          #do something to the image
  </code></pre>
  
  <p>Now, the script works in the first level of the <code>data</code> directory, but fails to work on <code>data</code>'s subdirectories.</p>
  
  <p>I tried using <code>os.path.join()</code>:</p>
  
  <pre><code>for (path, dirs, files) in os.walk("data/"):
      print os.path.join(path, dirs)
  </code></pre>
  
  <p>But that throws the following:</p>
  
  <pre><code>Traceback (most recent call last):
    File "bench.py", line 26, in &lt;module&gt;
      print os.path.join(path, dirs)
    File "/usr/lib/python2.7/posixpath.py", line 75, in join
      if b.startswith('/'):
  AttributeError: 'list' object has no attribute 'startswith'
  </code></pre>
  
  <p>In short, what I'd like to do is assemble a path from <code>data</code> to the image which includes <code>data</code>'s subdirectories. What's the best practice for doing this?</p>