os.walk and read file, having some problems with walking the path
<p>Here is the entirety of my code, I am trying to debug it, but it seems like I can't do any reading of files while using os.walk.  The problem is that without changing directories, I am hit with a error that 'out.csv' cannot be found, so i put in a chdir(), to move to that directory to read that file, but now it will only read that one file.  My estimate is there should be over 300+ of these files.  So it seems to stop after just the first file read after I put in the chdir().</p>

<pre><code>#! /usr/bin/env python
import csv, os

current = os.curdir
filescntd = 0 
avg = 0 

for root, dirs, files in os.walk('ARCIVE'):
  for file in files:
    base, ext = os.path.splitext(file)
    if ('csv' in ext):
      os.chdir(root)
      print root
      f = csv.reader(open('out.csv','rb'))
      count = 0 
      for row in f:
        if (count &gt;= 6 and count &lt;= 10):
          tempavg = 0 
          for i in row:
            tempavg += float(i)
            filescntd += 1
          tempavg /= len(row)
          avg += tempavg
        count += 1
      os.chdir(current)

os.chdir(current)
print '---'
avg /= 5.0 
print avg 
</code></pre>

<p>output:</p>

<pre><code>ARCIVE/8-15-11/temp/29033
---
0.02775
</code></pre>

<p>the option of filescntd is a little misleading, it is the amount of numbers averaged, and it comes to 40.</p>

<p>To clarify, what I want this program to do, is walk this directory tree and open all files that contain 'csv' in the extension, and read lines 6-10, and average those lines.  I am having problems with the walking the path and opening the files.</p>
