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

  • Home
  • SEARCH
  • 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 8144557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:25:19+00:00 2026-06-06T13:25:19+00:00

I want to make a program which would compare 2 .csv files, and print

  • 0

I want to make a program which would compare 2 .csv files, and print the rows that are in one of them, but not in the other. It basically works, but it stops working after performing 2 tasks in this program :/ I’m a Python beginner.

csv=open('c:\Users\***\Desktop\prvi.csv','r')
csv2=open('c:\Users\***\Desktop\drugi.csv','r')

list1=[]
choice=0
loop=0
while loop==0:
    choice=input('Odaberite zeljenu funkciju: \n1)\
 Usporedi Book1 sa Book2\n2) Usporedi Book2 sa Book1 \n3) Print Book1 \n4) Print Book2 \n5) Izlaz \nOdabir: ')
    if choice==1:
        for row in csv:
            if not row in csv2:
                list1.append(row)
                for row in list1:
                    print row
                    del list1[0:len(list1)]
    elif choice==2:
        for row in csv2:
            if not row in csv:
                list1.append(row)
                for row in list1:
                    print row
                    del list1[0:len(list1)]
    elif choice==3:
        for row in csv:
            print row
    elif choice==4:
        for row in csv2:
            print row
    elif choice==5:
        loop=1
  • 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-06T13:25:20+00:00Added an answer on June 6, 2026 at 1:25 pm

    I made an example of how to read these files, and also cleaned up your code a bit, because it hurted my eyes :D. You were using list1 in a very strange way. You put one line in it, display that line and then delete all the content of the list, which is always just one line, before moving to the next line. In your question you said that you just wanted to display the lines, so there is no need for a list. If you do need to keep track of the lines in a list, then just use list1.append(row) directly after print row, without all the extra for-loop and the deleting.

    # open lines as list, using read().split('\n') instead of readlines(),
    # because readlines() leaves '\n' after the lines.
    csv = open(r'c:\Users\***\Desktop\prvi.csv', 'r').read().split('\n')
    csv2 = open(r'c:\Users\***\Desktop\drugi.csv', 'r').read().split('\n')
    list1 = []    
    
    while True:
        # never use input(), unless you are using python 3
        choice = int(raw_input('Odaberite zeljenu funkciju: \n'
                               '1) Usporedi Book1 sa Book2\n'
                               '2) Usporedi Book2 sa Book1 \n'
                               '3) Print Book1 \n'
                               '4) Print Book2 \n'
                               '5) Izlaz \nOdabir: '))
        if choice == 1:
            for row in csv:
                if not row in csv2:
                    list1.append(row)
                    print row
            save_file()
        elif choice == 2:
            for row in csv2:
                if not row in csv:
                    list1.append(row)
                    print row
            save_file()
        elif choice == 3:
            for row in csv:
                print row
        elif choice == 4:
            for row in csv2:
                print row
        elif choice == 5:
            break
    
    def save_file():
        with open('output.txt', 'w') as f:
            f.write('\n'.join(list1))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, I want to make my program print out the date: 1/1/2009 But this
I want to make a program in python using pygtk, which would execute my
I want to make a program in C# which will go/login and do stuff
I want to make a program that will simulate a user browsing a site
I want to make a program that will read some number in string format
I want to make a simple program that sends random keystrokes to my other
Basically I want to make simple toggle program (that will be mapped to some
I want to make program that encrypts (later decrypts) user inputted string. Here is
I have a FindFile routine in my program which will list files, but if
I want to make a C program which randomly selects 6 numbers from numbers

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.