Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6386579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:02:39+00:00 2026-05-25T03:02:39+00:00

Here is the entirety of my code, I am trying to debug it, but

  • 0

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().

#! /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 >= 6 and count <= 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 

output:

ARCIVE/8-15-11/temp/29033
---
0.02775

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

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:02:39+00:00Added an answer on May 25, 2026 at 3:02 am

    Remove chdir and do f = csv.reader(open(os.path.join(root, 'out.csv'),'rb'))

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not entirely sure what's breaking here on this page: http://grandoaks.org/floor.html but it seems
I'm not entirely sure if I can do what I want here, but I
I'm trying to upload and parse json files using django. Everything works great up
im trying to edit a field using code instead of the wizard. im not
I am trying to compile a code in C++ using code from : https://stackoverflow.com/questions/5953979/sending-and-receiving-array-using-mpi-part-2
Here is my code, which takes two version identifiers in the form 1, 5,
Here's a coding problem for those that like this kind of thing. Let's see
Here is the scenario: I'm writing an app that will watch for any changes
I'm trying to hook up a keyboard shortcut for my chrome extension. I'm using
I am currently trying to do something similar to PSExec but entirely in Java.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.