以下脚本是读取以空格分开的字段(weight.txt)变成以逗号分隔(weight.csv)
#!/usr/bin/env python #-*- coding:utf-8 -*- # author jpuyy.com import csv reader = csv.reader(open('weight.txt', 'rb'), delimiter=' ', quoting=csv.QUOTE_NONE) writer = csv.writer(open('weight.csv', 'wb')) for row in reader: writer.writerow(row)
解决 csv 用 excel 打开乱码问题
import codecs file_obj = open(csv_name, "wb+") file_obj.write(codecs.BOM_UTF8) f = csv.writer(file_obj)
Leave a Reply