这是我的实际代码:
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)
Run Code Online (Sandbox Code Playgroud)
我希望在csv中以相同的顺序在fb_catalog_dict中使用相同的字典,问题是python使用不同的顺序fild创建我的csv文件,我该如何解决这个问题?