请教:python2 中文问题(读CSV文件)
python2.7.9
读取csv的其中一列得到这样的结果:
\xc9\xcc\xc6\xb7\xb2\xe2\xca\xd4
导致存储到mysql也是这个十六进制串
我怎么才能存储为中文?
with open('123.csv','rb') as cf:
reader = csv.reader(cf)
for row in reader:
if reader.line_num==240:
list1=['tradeTime','productName']
tradeTime=row[0].replace('`','')
productName=row[20].replace('`','').encode("gb2312")
list2=[tradeTime,productName]
logging.debug("productName={0}".format(productName))
sorderData=dict(zip(list1,list2))
logging.debug(sorderData)
日志如下:
2015-05-28 13:26:33,244 productName=商品测试
2015-05-28 13:26:33,244 {'tradeTime': '2015-05-15 11:06:47', 'productName': '\xc9\xcc\xc6\xb7\xb2\xe2\xca\x
导致存储到数据库中的'productName为\xc9\xcc\xc6\xb7\xb2\xe2\xca\xd4
请问如何存储为“商品测试”