csv文件的读取写法 from Udacity
长版本
import unicodecsv
enrollments_filename = 'C:\\Users\\xxxxx\\Desktop\\try.csv'
enrollments = []
f = open(enrollments_filename, 'rb')
reader = unicodecsv.DictReader(f)
for row in reader:
enrollments.append(row)
print(enrollments)
f.close() #需要关闭文件
简化版本
import unicodecsv
enrollments_filename = 'C:\\Users\\xxxxx\\Desktop\\try.csv'
with open(enrollments_filename, 'rb') as f: #使用完后文件自动关闭
reader = unicodecsv.DictReader(f)
enrollments = list(reader) #自动生成list
print(enrollments)