Compare 2 files - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Compare 2 files (/thread-39392.html) |
Compare 2 files - tslavov - Feb-10-2023 What is the Script in Python to Print Field = 2 of "File1.txt" and Field = 4 of "File2.txt" When Field = 1 is "A4" of "File1.txt" is equal Field = 1 is "A4" of "File2.txt" File 1 | A1| A| Ab| Abc| ABCD| ABCDE| ABCDEF| | A2| Ab| Abc| ABCD| ABCDE| ABCDEF| | A3| Abc| ABCD| ABCDE| ABCDEF| | A4| ABCD| ABCDE| ABCDEF| File 2 | A1| A| Ab| Abc| ABCD| ABCDE| ABCDEF| | A2| A| Ab| Abc| ABCD| ABCDE| ABCDEF| | A3| A| Ab| Abc| ABCD| ABCDE| ABCDEF| | A4| A| Ab| Abc| ABCD| ABCDE| ABCDEF| Answer - ABCD (File 1) and ABCD (File 2) RE: Compare 2 files - Larz60+ - Feb-10-2023 what have you tried so far? Please post your code working or not. RE: Compare 2 files - ibreeden - Feb-12-2023 Hi @tslavov , Welcome to the forum. The aim of this forum is to help people to learn Python. So no complete programs will be given. You have to produce a program and if it does not do what you expected, then we will help you. I see you have to read two files. So the first task is: write a program to open both files and read them line by line. I suggest you use open() and readline() for this. Please show us what you make of it. |