我一直在使用python 2.6。当我正在编写一个python程序来处理来自sql server的查询结果(以csv格式)时。我发现它不支持unicode。python 3.1.3是否支持csv模块中的unicode?
当我运行csv文件的程序,错误POP操作起来说:
for row in csvReader:
Error: line contains NULL byte
后,我保存CSV文件用UltraEdit ANSI/ASCII格式,程序运行正常。
我想包括编码选项,但它失败:
csvReader = csv.reader(open(fname, mode='rb', encoding='unicode'), delimiter=',')
TypeError: 'encoding' is an invalid keyword argument for this function
csvReader = csv.reader(open(fname, mode='rb', encoding='utf-8'), delimiter=',')
TypeError: 'encoding' is an invalid keyword argument for this function
不知巨蟒-3支持这个unicode阅读。它可以为我节省很多工作。
你为什么不直接从蟒蛇访问SQL? – Kimvais 2012-02-29 06:53:44
Python 3.1.3的'open' *绝对*支持和'encoding ='参数,所以要么使用不同版本的Python,要么意外地覆盖了'open'函数。 – 2012-02-29 07:02:38
我说我正在使用python 2.6。那么Python 3.1.3不会有这个问题? – lamwaiman1988 2012-02-29 07:05:45