报错1:
Traceback (most recent call last):
  File "handle.py", line 24, in <module>
    writer.writerow(row)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-4: ordinal not in range(128)
row中有中文
解决:
import sys
reload(sys)
sys.setdefaultencoding('utf8')
报错2:
csv文件能写入成功,但是文件用excel打开,显示的是乱码.
解决:
import codecs
with open('test.csv', 'rb') as f:
  f.write(codecs.BOM_UTF8)
  writer = csv.writer(f)
...
后面是一样的使用