使用 python list即可,因为list可以加入不同的数据类型的数据。
results = list()
lines = open('cvs_file', 'r').readlines()
for line in lines:
elements = line.strip().split(',') # supposed limiter is ','
for e in elements:
try:
results.append(float(e))
except:
continue
# Here results will contains all splitted elements
# all elements are string read from cvs file, so you need to
# converse it with float operator. But if element is read string
# we can catch conversion exception and throw it anyway.
python的csv模块可用