Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save tablib dataset as csv file?

I have created a dataset using tablib.

out_dict is a dictionary file

headers = out_dict.keys()
data = tablib.Dataset(out_dict.values(), headers=headers)

How can I save it as a csv file in the same format?

like image 470
Gokul Sundeep Avatar asked Sep 06 '25 17:09

Gokul Sundeep


1 Answers

According to the Exporting Data tablib documentation, a dataset can be exported in a number of different formats. To export to CSV format use:

data.export('csv')

Or directly to a file using:

with open('output.csv', 'w', newline='') as f_output:
    f_output.write(data.csv)
like image 192
Martin Evans Avatar answered Sep 09 '25 05:09

Martin Evans