Skip to main content

Complete file compare tool/software in python

Beyondcompare project in python 


File compare tool/software in python. It works like beyondcompare software. It is a file compare project made by me. Kindly go through the code. It selects the files dynamically using file dialogue option using button. The file absolute path is seen on textboxes and the compare button generates the difference between two files are prints difference in the third file. The GUI is made in 'tkinter' library of python. In the below mentioned program/project you will learn 

1) how to design GUI in python
2) how to reply to button click events
3) how to bind the values(input of file dialogue from user) to textboxes
4) how to use file dialogue
5) how to get directory path using full file path
6) how to get file name from full file path
7) logic to find the difference between two files

Below is the code in which user selects 2 different files as a input and it will generate the difference and finally print the difference in another file. You can generate the difference in any file extension as you want. You have to explicitly mention the file extension in the code. 

The code works for as many numbers of records or huge text data. Also the program execution is very faster.

Here is the code:


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()
    print(filename)
    txt1.delete(0,END)
    txt1.insert(0,filename)
    
def browsefunc2():
    filename = filedialog.askopenfilename()
    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(first) as f1:
        first_line1 = f1.readline()    
        print(first_line1)
    with open(first, 'a') as file_out:
        file_out.write(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.txt', 'a') as file_out2:
        for line2 in new_extra:
            file_out2.write(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

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...

RGB Color Demo in C# using scrollbar as a slider horizontally

Below is the project which contains 3 horizontal scrollbars if we slides the scrollbars the background color of the form is changing accordingly. first scrollbar is adding red color, second adding green and third one adding blue upon scrolling or sliding. Take 3 horizontal scrollbars and assign them maximum value of 255(from 0) to each one. Below is the designer 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 Color_RGB_demo {     public partial class Form1 : Form     {         public Form1()         {             InitializeComponent();                   }         public...

Get/Access JIRA/JIRA API data using python

 Below is the program which will guide you on how to access the JIRA API data using python. First, you need to create a token for JIRA. You need to install the following libraries using the following commands: pip install requests pip install json-excel-converter And the code is: # Import the required libraries import requests from requests.auth import HTTPBasicAuth import json import pandas as pd from json_excel_converter import Converter from json_excel_converter.xlsx import Writer # URL to Search all issues. url = "YOUR JIRA URL" # Create an authentication object,using # registered emailID, and, token received. auth = HTTPBasicAuth("email-d",                      "jira token created") # The Header parameter, should mention, the # desired format of data. headers = {     "Accept": "application/json" } # Mention the JQL query. # Here, all issues, of a project, are # fetched,as,no criteria is mentioned. query = { ...