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 6781701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:39:19+00:00 2026-05-26T16:39:19+00:00

System info: Python 2.7.2 MAC OSX 10.7.2 Problem (+background): I have a large ‘.csv’

  • 0

System info:
Python 2.7.2
MAC OSX 10.7.2

Problem (+background):
I have a large ‘.csv’ file (~1 gig) which needs some minor editing. Every value in the 5th column needs to be 5 characters long (some are 4 characters long, and need a ‘0’ placed in front of them). The code (shown below) reports no errors when run, but stops writing with approximately 100 lines in the file left (thereby losing some crucial data!). Anyone know why this is happening?

I’ve re-created the ‘read_file.csv’ and inspected it, but I don’t see anything out of place. The code always aborts in the same location, but I don’t understand why?

import csv

path = '/Volumes/.../'

r = csv.reader(open(path + 'read_file.csv','rU'))
f =  open(path + 'write_file.csv', 'wb')

writer = csv.writer(f)

for line in r:

    if len(line[5]) == 4:
        line[5] = '0' + line[5]

    writer.writerow((line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7]))
  • 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-26T16:39:19+00:00Added an answer on May 26, 2026 at 4:39 pm

    Either close the output file after writing it, or write the output in a with context which will always close the file even if an error occurs:

    with open('path + 'write_file.csv', 'wb') as f:
        writer = csv.writer(f)
        for line in r:
            ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

System Info: Mac OSX 10.7, Python 2.6.7, Plone 4.0.7 I'm creating an uninstall profile
Is there any method / API defined to collect system info in osx. I
I have a python program in an embedded system that needs to write to
I have a lovely AppleScript droplet which performs OCR of a PDF file using
I want to create a simple Mac application bundle which calls a simple Python
System.IO.BinaryReader reads values in a little-endian format. I have a C# application connecting to
System.BitArray only implements the non-generic IEnumerable, which returns an Object for the IEnumerator.Current property.
System.Environment.OSVersion does not appear to indicate which Edition of Windows 2003 is installed (Standard,
System: Windows XP SP3, .NET 3.5, 4GB RAM, Dual 1.6gHz I have a WPF
How can we query connected USB devices info in Python? I want to get

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.