巨蟒3.X
处理UTF8物料清单+标题
令人沮丧的是
csv
模块无法轻松获取头文件,UTF-8bom(文件中的第一个字符)也有一个错误。
这对我来说很管用
csv公司
模块:
import csv
def read_csv(self, csv_path, delimiter):
with open(csv_path, newline='', encoding='utf-8') as f:
# https://bugs.python.org/issue7185
# Remove UTF8 BOM.
txt = f.read()[1:]
# Remove header line.
header = txt.splitlines()[:1]
lines = txt.splitlines()[1:]
# Convert to list.
csv_rows = list(csv.reader(lines, delimiter=delimiter))
for row in csv_rows:
value = row[INDEX_HERE]