使用 python2.7 在 csv 文件中写入中文单词

write chinese words in csv file using python2.7

I am trying to write Chinese words like 花花公子昊天鞋类专营店 in a CSV file in python, but not able to do it. I tried solution given here("issues with writing Chinese to csv file in Python"). Any help will be appreciated.

模块 unicodecsv 对此有帮助(您可以使用 pip 安装它):

import unicodecsv
w = unicodecsv.writer(open("test.csv", "w"))
w.writerow((u"花花公子昊天鞋类专营店", 78.10))
del w

生成的 csv 文件在 OpenOffice 中成功打开。

您也可以在Python中阅读:

r = unicodecsv.reader(open("test.csv", "rb"))
for row in r:
    print row[0], row[1]

当 运行 时,它应该打印:

(user@motoom) ~/Prj/python $ python chinesecsv.py

花花公子昊天鞋类专营店 78.1