python csv file write, which prevents json csv comma impact divided by preventing distortion open excel csv

import csv

Open with ( "baiyibutie.csv", "A", encoding = " UTF--SIG. 8 ", NEWLINE = "") AS FP: Parameters marked red # is opened in order to solve problems with distortion excel, plus the parameter excel will open with normal display, without distortion 
fieldnames = [ 'name', ' price', 'cate', 'url', 'data'] # this is the content of the title bar
writer = csv.DictWriter (fp, fieldnames = fieldnames) # the title bar is added to the csv file
writer.writeheader () # this line is written in the title bar of the first row, on the outside of the for loop, otherwise there will be a number of the title bar
   writer.writerow({'name': result["shortName"], 'price': price, 'cate': cate, 'url': "http:" + result["itemUrl"], 'data': json.dumps(result)})

Guess you like

Origin www.cnblogs.com/qiaoer1993/p/12604509.html