Python script to compare 2 files

0 votes
Can you please let me know if you have some python script that compares 2 text files, irrespective of the type and write the difference between that 2 files in text format in some other file.
Jul 31 in Python by Shubhangi
21 views

1 answer to this question.

0 votes

Refer the given code and let us know in case you have any concerns.​

with open('first_file.txt', 'r') as file1:
    with open('second_file.txt, 'r') as file2:
        difference = set(file1).difference(file2)
        difference.discard('\n')
        with open('diff.txt', 'w') as file_out:
        for line in difference:
            file_out.write(line)
answered Jul 31 by Arpit

Related Questions In Python

0 votes
1 answer
0 votes
1 answer

How can I compare the content of two files in Python?

Assuming that your file unique.txt just contains ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,720 points
93 views
0 votes
1 answer

How to import other Python files?

importlib is recent addition in Python to ...READ MORE

answered Jul 27, 2018 in Python by Priyaj
• 56,520 points
44 views
+3 votes
2 answers

how to print array integer without [] bracket in python like result = 1,2,3,4,5

Hey @abhijmr.143, you can print array integers ...READ MORE

answered Aug 4, 2018 in Python by Omkar
• 67,380 points

edited Aug 8, 2018 by Omkar 635 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 222 views
+4 votes
6 answers
+3 votes
5 answers

How to read multiple data files in python

Firstly we will import pandas to read ...READ MORE

answered Apr 6, 2018 in Python by DeepCoder786
• 1,700 points
1,687 views
0 votes
1 answer

I'm using Python 2.7 to convert an XML response (from a REST call to Atlassian Fisheye) into an HTML table.

You don't have a template matching tabularQueryResult in your ...READ MORE

answered Oct 4, 2018 in Python by Priyaj
• 56,520 points
34 views