python 写入csv防止乱码

# coding: utf-8

import codecs
import os
os.chdir("F:\project\predict")
import csv
csvfile = open('csv_test.csv', 'wb')

csvfile.write(codecs.BOM_UTF8) #防止乱码
writer = csv.writer(csvfile)

writer.writerow(['姓名', '年龄', '电话'])

data = [
    ('小王', '25', '1520586115'),
    ('小李', '18', '1368547259')
]
writer.writerows(data)

csvfile.close()

你可能感兴趣的:(Python,python,乱码,csv)