编码错误(csv文件+mysql)

2024-06-06 08:24:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我编码有问题。

mycsv文件(编码UTF-8):

Id,Title,FullDescription
55408086,Injection Moulding Product Designer,• Tooling experience is an advantage • Automotive experience is as must

以及mypython代码(简化):

# -*- coding: utf-8 -*-
import csv
import codecs

with codecs.open('D:\\Downloads\\Train_rev2.csv', 'rb', encoding='utf-8') as csv_file:
    data = csv.reader(csv_file, delimiter=',')
    data.next()
    for row in data:
        print (row[0], row[1], row[2])

此打印:

('55408086', 'Injection Moulding Product Designer', '\xe2\x80\xa2 Tooling experience is an advantage \xe2\x80\xa2 Automotive experience is as must')

然后,我将数据插入数据库(MYSQL编码UTF-8 Unicode(utf8)),并且我得到的数据编码错误:

^{pr2}$

Tags: csvan编码dataisasproducttooling