Sum fixes

This commit is contained in:
2022-12-26 01:33:18 -03:00
parent de88d9fe0f
commit 603a0f2c69
2 changed files with 29 additions and 18 deletions

View File

@ -3,24 +3,35 @@
#... 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 main():
# Open the input files
file1 = open("file1.csv", "r", encoding="utf8")
file2 = open("file2.csv", "r", encoding="utf8")
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())
# Read the contents of the input files into variables
text1 = file1.readlines()
text2 = file2.readlines()
# find the lines that are present only in one of the files
only_in_file1 = lines1 - lines2
only_in_file2 = lines2 - lines1
# Close the input files
file1.close()
file2.close()
# 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)
# Create a set of the lines in each file
lines1 = set(text1)
lines2 = set(text2)
# Calculate the difference between the sets
diff = lines2.difference(lines1)
compare_csv_files('file1.csv', 'file2.csv')
# Open the output file
output_file = open("diff.csv", "w", encoding="utf8")
# Write the difference to the output file
for line in diff:
output_file.write(line)
# Close the output file
output_file.close()
if __name__ == "__main__":
main()