27 lines
836 B
Python
27 lines
836 B
Python
#This diffs two csv files, It's useful for mods and stuff.
|
|
|
|
#... I haven't actually tried this yet, it might work, it might not.
|
|
# If it doesn't. Call my number (It's hidden in your ear!).
|
|
|
|
import csv
|
|
|
|
def compare_csv_files(file1, file2):
|
|
# read the files line by line and store them in sets
|
|
with open(file1, 'r') as f1:
|
|
lines1 = set(f1.readlines())
|
|
with open(file2, 'r') as f2:
|
|
lines2 = set(f2.readlines())
|
|
|
|
# find the lines that are present only in one of the files
|
|
only_in_file1 = lines1 - lines2
|
|
only_in_file2 = lines2 - lines1
|
|
|
|
# write the lines to a new file
|
|
with open('comparison_result.csv', 'w') as result_file:
|
|
writer = csv.writer(result_file)
|
|
writer.writerows(only_in_file1)
|
|
writer.writerows(only_in_file2)
|
|
|
|
|
|
compare_csv_files('file1.csv', 'file2.csv')
|