3

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?

0xInfection
  • 2,676
  • 1
  • 19
  • 34
  • 1
    Read [exporting-data `Comma-Separated Values`](http://docs.python-tablib.org/en/master/tutorial/#exporting-data) – stovfl Jan 31 '19 at 12:17

1 Answers1

3

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)
Martin Evans
  • 45,791
  • 17
  • 81
  • 97
  • Seems to be that way now: `with open('my-data.csv', 'w', newline='') as f: f.write(dataset.csv)` – Anthony Feb 09 '22 at 13:50