I want to suggest that you first combine all your CSVs into a single CSV, make sure that's correct, then convert the single CSV to XML:
- you'll be able to verify the intermediate, combined result
- issues like overwriting data simply disappear when any file is only being written to once
This takes more lines of code, and I find it's easier to get correct:
import csv
Combined_CSV = "combined.csv"
# I'm not sure how you get your final list of CSV paths and file names
csv_fnames = ["input1.csv", "input2.csv"]
all_rows = []
for csv_fname in csv_fnames:
with open(csv_fname, newline="") as f:
reader = csv.reader(f)
next(reader) # Skip header
all_rows.extend(list(reader))
with open(Combined_CSV, "w", newline="") as f:
writer = csv.writer(f)
writer.writerows(all_rows)
# Take a moment, verify all the data looks good, pat yourself on the
# back, comment-out the following two lines, move on to converting
# the data to XML
print(f"combined all rows; inspect {Combined_CSV}")
sys.exit(0)
all_rows = []
with open(Combined_CSV, newline="") as f:
reader = csv.reader(f)
all_rows = list(reader)
with open("Client.xml", "w") as f:
f.write("\n".join([convert_row(row) for row in all_rows]))