I slightly changed the input data into a form which would make more sense technically speaking.
In addition I removed the ResultId()
since this seems to be a special datatype which needs to be converted into a string separately before doing any further data handling after receiving the responses from the database.
However, I would suggest doing something like this using csv.Dictwriter()
:
import csv
# changed sample data key `Test` in order to have this key equal in all responses
# which would make more sense technically
data = [{u'Test': u'Result1', u'_id': '987600234565ade', u'bugseverity': u'major'},
{u'Test': u'Result2', u'_id': '987600234465ade', u'bugseverity': u'minor'},
{u'Test': u'Result3', u'_id': '9876002399999de', u'bugseverity': u'minor'}]
# define the column names
fieldnames = ['Test', '_id', 'bugseverity']
with open('dict.csv', 'w') as f:
writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writeheader()
for d in data:
for key, value in d.items():
writer.writerow(d)
Giving dict.csv
as output:
Test,_id,bugseverity
Result1,987600234565ade,major
Result1,987600234565ade,major
Result1,987600234565ade,major
Result2,987600234465ade,minor
Result2,987600234465ade,minor
Result2,987600234465ade,minor
Result3,9876002399999de,minor
Result3,9876002399999de,minor
Result3,9876002399999de,minor
0
solved Using Python need to print in csv format