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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:17:56+00:00 2026-06-11T16:17:56+00:00

I am using Python Version 3.2. Have the following code: for row2 in reader2:

  • 0

I am using Python Version 3.2. Have the following code:

for row2 in reader2:
    for row1 in reader1:
        if row1['identification_column'] == row2['identification_column']:
            row2['updated_col'] = row1['updated_col']
    writer.writerow(row2)

reader1 is a csv.DictReader object that looks like the following:

    identification_column,type

    1, bike                       
    2, guitar
    3, drums
    4, airplane
    5, computer

reader2 is similar to reader1, except a much longer and more comprehensive file.

The problem is this:

I run through all of the inner loop, and, if the program doesn’t find a match, it doesn’t write the line, and then increment the outer loop like I thought it would. It just stops. Initially it threw me an error until I read a post here where someone suggested adding “extrasaction = ‘ignore'” to the writer declaration statement. But that didn’t solve my problem.

I would greatly appreciate any feedback for fixing this logic. In my mind the following was what would be happening:

A) In the case where the inner loop does not find the value in question from the outer loop, the program outputs the line in the outer loop with no changes

B) In the case where the inner loop has the exact value that the outer loop is iterating over, change the values in one of the columns in the row and then output that row

I can see that as is, the program just stops after the first iteration of the inner loop, but I don’t understand why this is the case.

  • 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-11T16:17:58+00:00Added an answer on June 11, 2026 at 4:17 pm

    reader1 and reader2 are file objects (wrapped in a csv DictReader). Those are iterators that can only be read once (until you’re at the end of the file), so there’s nothing for the next for loop to do.

    Solution:

    Read the file into a list and use that to refresh the DictReader:

    read_1 = myfile1.readlines()
    for row2 in reader2:
        reader1 = csv.DictReader(read_1)
        for row1 in reader1:
            # etc.
    

    Even better, read that csv file into a list of dictionaries once – that should be faster:

    reader1 = list(csv.DictReader(myfile))
    for row2 in reader2:
        for row1 in reader1:
            # etc.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code (using Python 2.7): # shared command line options, like
I have the following Python code: import xml.dom.minidom import xml.parsers.expat try: domTree = ml.dom.minidom.parse(myXMLFileName)
I am using Python 2.6, and am having difficulty understanding why the following code
I have a number of projects using git for version control. Some are python
I have the following XML document that I have to parse using python's minidom:
I am using an API which provides a Java version but not a Python
Using Python's csv module, is it possible to read an entire, large, csv file
I am using the following code to dynamically create an INPUT element and assign
I'm running into a problem with the following Python 3.2.2 code. The code is
I'm trying to cluster some data with python and scipy but the following code

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.