Skip to main content

complete file compare software in python with classification

complete file compare software in python with classification


In previous article i have posted code for file comapre in python in this article i have have modified the code a lot. It is full working code. Kindly verify and revert if you like it. Also i have classified the records which are old ones and which are from new one in difference file.

from tkinter import filedialog

from tkinter import *

import os



window = Tk()

window.title("My File Compare...")

window.geometry('750x200')

lbl1 = Label(window, text="Select Old File Path")

lbl1.grid(column=0, row=0)

txt1 = Entry(window,width=80)

txt1.grid(column=1, row=0)

lbl2 = Label(window, text="Select new File Path")

lbl2.grid(column=0, row=2)

txt2 = Entry(window,width=80)

txt2.grid(column=1, row=2)



def browsefunc1():

    filename = filedialog.askopenfilename(initialdir = "D:/QA/")

    print(filename)

    txt1.delete(0,END)

    txt1.insert(0,filename)

   

def browsefunc2():

    filename = filedialog.askopenfilename(initialdir = "D:/QA/")

    print(filename)

    txt2.delete(0,END)

    txt2.insert(0,filename)

   

btn = Button(window, text="choose old file", command=browsefunc1)

btn.grid(column=2, row=0)

btn1 = Button(window, text="choose new file", command=browsefunc2)

btn1.grid(column=2, row=2)





def compare_files():

    first = txt1.get()

    second = txt2.get()

    old = open(first,'r')

    new = open(second,'r')

    #in new but not in old

    new_extra = set(new) - set(old)

   

    with open(second) as f1:

        first_line1 = f1.readline()   

        #print(first_line1)

    with open(os.path.dirname(os.path.abspath(second))+'/'+os.path.splitext(os.path.split(second)[1])[0]+'_DIFFERENCE.csv', 'a') as file_out:

        file_out.write('Change Table,'+first_line1)

        #print(first_line1)

    # write to output files   

    with open(os.path.dirname(os.path.abspath(second))+'/'+os.path.splitext(os.path.split(second)[1])[0]+'_DIFFERENCE.csv', 'a') as file_out2:

        for line2 in new_extra:

            file_out2.write('NEW TABLE,'+line2)

            #print(first_line1)

    old.close()

    new.close()

    first = txt1.get()

    second = txt2.get()

    old = open(first,'r')

    new = open(second,'r')

    #in old but not in new

    old_extra = set(old) - set(new)

    #with open(os.path.dirname(os.path.abspath(second))+'/'+os.path.splitext(os.path.split(second)[1])[0]+'_DIFFERENCE.csv', 'a') as file_out2:

       

    with open(os.path.dirname(os.path.abspath(second))+'/'+os.path.splitext(os.path.split(second)[1])[0]+'_DIFFERENCE.csv', 'a') as file_out2:

        #file_out2.write('in old and not in new\n')

        for line2 in old_extra:

            file_out2.write('OLD TABLE,'+line2)

            #print(first_line1)



btn2 = Button(window, text="Compare file", command=compare_files)

btn2.grid(column=1, row=3)

window.mainloop()

Comments

Popular posts from this blog

Add, remove, search an item in listview in C#

Below is the C# code which will help you to add, remove and search operations on listview control in C#. Below is the design view of the project: Below is the source code of the project: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Treeview_control_demo {     public partial class Form2 : Form     {         public Form2()         {             InitializeComponent();             listView1.View = View.Details;                   }         private void button1_Click(object sender, EventArgs e)         {             if (textBox1.Text.Trim().Length == 0)...

MySQL practical Tutorials part 9- SQL not operator, SQL Not Like, SQL greater than, SQL less than greater than operator

 ========================================================================= Not Equal SELECT title FROM books WHERE released_year = 2017;   SELECT title FROM books WHERE released_year != 2017;   SELECT title, author_lname FROM books;   SELECT title, author_lname FROM books WHERE author_lname = 'Harris';   SELECT title, author_lname FROM books WHERE author_lname != 'Harris'; ========================================================================= Not Like SELECT title FROM books WHERE title LIKE 'W';   SELECT title FROM books WHERE title LIKE 'W%';   SELECT title FROM books WHERE title LIKE '%W%';   SELECT title FROM books WHERE title LIKE 'W%';   SELECT title FROM books WHERE title NOT LIKE 'W%'; ========================================================================= Greater Than SELECT title, released_year FROM books ORDER BY released_year;   SELECT title, released_year FROM books  WHERE released_year > 2000 ORDER BY release...

MULTIPLEXER , Design & Implement the given 4 variable function using IC74LS153. Verify its Truth-Table

TITLE: MULTIPLEXER   AIM: Design & Implement the given 4 variable function using IC74LS153. Verify its Truth-Table.   LEARNING OBJECTIVE: ·        To learn about IC 74153 and its internal structure. ·        To realize 8:1 MUX and 16:1 MUX using IC 74153.   COMPONENTS REQUIRED: IC 74153, IC 7404, IC 7432, CDS, wires, Power supply. IC PINOUT:            1)     IC 74153 2)      IC 7404:                                              3) IC 7432 THEORY:   ·        Multiplexer is a combinational circuit that is one of the most widely used in digital design. ·        The multiplexer is a data selector which gates one out of several inputs to a sin...