row = {'colA': 'var1', 'colB': 'var2'} fieldnames = ['colA', 'colB'] with open('file.csv', 'a', encoding='utf8', newline='') as file: writer = csv.DictWriter(file, fieldnames=fieldnames) writer.writerow(item)