def write_key_value_file(csvfile,dictionary,append=False):
"""Writes a dictionary to a writable file in a CSV format
Args:
csvfile (FILE): Writable file
dictionary (dict): Dictionary containing key-value pairs
append (bool, optional): Writes `key,value` as fieldnames if False
Returns:
None: No return
"""
writer = csv.writer(csvfile, delimiter=',')
if not append:
writer.writerow(['key','value'])
for key,val in dictionary.items():
writer.writerow([key,val])
评论列表
文章目录