【发布时间】:2018-07-29 14:15:56
【问题描述】:
这是我的实际代码:
import csv
fb_catalog_dict = {
"id":"",
"title":"",
"description":"",
"availability":"",
"condition":"",
"price":"",
"link":"",
"image_link":"",
"brand":"",
"additional_image_link":"",
"age_group":"",
"color":"",
"gender":"",
"item_group_id":"",
"google_product_category":"",
"material":"",
"pattern":"",
"product_type":"",
"sale_price":"",
"sale_price_effective_date":"",
"shipping":"",
"shipping_weight":"",
"size":"",
"custom_label_0":"",
"custom_label_1":"",
"custom_label_2":"",
"custom_label_3":"",
"custom_label_4":"",
}
with open('mycsvfile.csv', 'wb') as f: # Just use 'w' mode in 3.x
w = csv.DictWriter(f, fb_catalog_dict.keys())
w.writeheader()
w.writerow(fb_catalog_dict)
我想在 csv 中以相同的顺序在 fb_catalog_dict 中创建相同的字典,问题是 python 为我创建具有不同顺序字段的 csv 文件,我该如何解决这个问题?
【问题讨论】:
标签: python csv dictionary export-to-csv