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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:25:25+00:00 2026-06-16T01:25:25+00:00

When I try to run import csv import sys import operator fieldnames = [A,B,C,D,E]

  • 0

When I try to run

import csv
import sys
import operator

fieldnames = ["A","B","C","D","E"]
surveyfile = open("source.csv", "r")
left_file = open("left.csv",'wb')
right_file = open("right.csv",'wb')


left_reader = csv.DictReader(surveyfile, fieldnames=fieldnames, delimiter=",")
left_writer = csv.DictWriter(left_file, fieldnames, delimiter=",")
sortedlefts = sorted(left_reader,key=lambda x:float(x["B"]))

right_reader = csv.DictReader(surveyfile, fieldnames=fieldnames, delimiter=",")
right_writer = csv.DictWriter(right_file, fieldnames, delimiter=",")
sortedrights = sorted(right_reader,key=lambda x:float(x["B"]), reverse=True)

for row in sortedlefts:
    if row["E"] == "l":
        left_writer.writerow(row)


for row in sortedrights:
    if row["E"] == "r":
        right_writer.writerow(row)

Nothing happens in the “right.csv” file. But if I take everything that has to do with making the right.csv file out and put it into a different program, it works fine. Do I need to end that for loop? Is it some problem with using the same reader for both?

  • 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-06-16T01:25:26+00:00Added an answer on June 16, 2026 at 1:25 am

    The input file is likely exhausted, so yes it has to do with re-using the reader instance.

    Not sure why you expect the reader object to magically know when it’s supposed to re-deliver the data.

    You need to be more explicit about this, I would simply recommend re-creating the reader as needed.

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

Sidebar

Related Questions

When I run a mysqldump command on my database and then try to import
I try to run #!/usr/bin/env python import os from numpy import * b= ones((3,
When I try to run this code: import java.io.*; import java.util.*; public class TwoColor
When I try to run this code... module Main where import qualified Data.Text.Lazy.IO as
When I try to run domain.com:8080/solr/dataimport?command=full-import , I get the error Indexing failed. Rolled
I try to run sample code but got some error: The import javax.microedition.contactless cannot
I try run jconsole with jar that contains my classes like: cd C:\Program Files\Java\jdk1.6.0_26\bin
I'm getting this error when I try run DB:Rake : ** Invoke db:migrate (first_time)
I try to run a medium sized programm with a lot of external jars
I try to run the following raw query in android, it seems not work

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.