封装了2种方式读取csv(数组和字典)
class CsvHelper(object):
def read_data(self, f, encoding="utf8"):
"""
读csv文件作为普通list
:param f:
:return:
"""
data_ret = []
with open(f, encoding=encoding, mode='r') as csv_file:
csv_data = csv.reader(csv_file)
for row in csv_data:
data_ret.append(row)
return data_ret
def read_data_as_dict(self, f, encoding="utf8"):
"""
读csv文件作为普通list
:param f:
:return:
"""
data_ret = []
with open(f, encoding=encoding, mode='r') as csv_file:
csv_dict = csv.DictReader(csv_file)
for row in csv_dict:
data_ret.append(row)
return data_ret