Knowledge Forum

Welcome!

This community is for professionals and enthusiasts of our products and services.
Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

1

Export CSV file with customer fields

Avatar
Harshit Trivedi


Export CSV file with customer fields
Avatar
Discard
1 Answer
0
Avatar
Harshit Trivedi
Best Answer

from io import StringIO

from csv import DictWriter

import csv




ls=[]

ls.append({"key":value,"key2":value})


datas=ls

field_name=['key1','key2']

with open('/tmp/Demo.csv','w') as file:

   csvwriter=DictWriter(file,field_name,'\t')

   csvwriter.writeheader()

   csvwriter.writerows(datas)

   file.close()


Avatar
Discard

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!