mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-31 17:55:01 +00:00
aider: Added diff_files.py
script that reads two file names from the command line, reads the contents of the files, and then uses the difflib
module to print their differences.
# Context: USER: read 2 files named on the cmd line, use difflib to print their differences ASSISTANT: To achieve this, we'll create a new Python script that reads two file names from the command line, reads the contents of the files, and then uses the `difflib` module to print their differences. 1. Create a new Python script called `diff_files.py` in the `aider` directory. 2. Import the necessary modules: `sys` and `difflib`. 3. Read the file names from the command line arguments. 4. Read the contents of the files. 5. Use `difflib.unified_diff()` to generate the differences. 6. Print the differences. Here's the code for the new `diff_files.py` script: ```python aider/diff_files ^C KeyboardInterrupt USER: put it in `aider/diffs.py`
This commit is contained in:
parent
130f73c864
commit
efb903303f
1 changed files with 23 additions and 0 deletions
|
@ -0,0 +1,23 @@
|
|||
import sys
|
||||
import difflib
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 3:
|
||||
print("Usage: python diffs.py file1 file2")
|
||||
sys.exit(1)
|
||||
|
||||
file1, file2 = sys.argv[1], sys.argv[2]
|
||||
|
||||
with open(file1, 'r') as f1:
|
||||
content1 = f1.readlines()
|
||||
|
||||
with open(file2, 'r') as f2:
|
||||
content2 = f2.readlines()
|
||||
|
||||
differences = list(difflib.unified_diff(content1, content2, fromfile=file1, tofile=file2))
|
||||
|
||||
for line in differences:
|
||||
sys.stdout.write(line)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue