Answer the question
In order to leave comments, you need to log in
How to write from db to csv?
Good evening.
Please tell me, I have a tuple obtained from the database consisting of 4 elements for example ("LLC horns and hooves", "# 123", "12.20.2016", "12.20.2017")
I need to write uX in csv so that each the element of the tuple was in its cell. How to do it ?
with open('list_to_csv.csv', 'w') as csv_file:
csv_writer = csv.writer(csv_file)
for num,item in enumerate(a):
csv_writer.writerow(a[num])
Answer the question
In order to leave comments, you need to log in
You probably need a different CSV dialect . Try playing with the dialect parameter in csv.writer , try csv.excel, csv.excel_tab, csv.unix_dialect values, or text strings like "excel". The format of the output CSV will then change. Try until you get separate cells.
If it does not help, then you will have to manually set the delimiter and quotechar parameters.
Of course, I just recently started learning the language, so maybe I didn’t understand something, but for writing to csv, it’s easier csv_file.write(';'.join(a))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question