python - Only delimit values with quotes and not the headers -
i using python csv module write csv file. have used following code create object writing csv file
writer = csv.writer(stringio, quotechar='"', quoting=csv.quote_all) headers = ['heading1','heading2'] writer.writerow(headers) values=['value1','value2'] writer.writerow(values) but want put double quotes around values , not headers.
for example want output follows:
heading1,heading2 "value1","value2" but following
"heading1","heading2" "value1","value2" please can suggest how can csv file quotes around values , not headers?
write headers separately, creating new csv.writer() rows:
writer = csv.writer(stringio) headers = ['heading1', 'heading2'] writer.writerow(headers) writer = csv.writer(stringio, quotechar='"', quoting=csv.quote_all) values=['value1', 'value2'] writer.writerow(values) csv.writer() objects have no way of switching between dialects. create new object if have use different dialect rows.
Comments
Post a Comment