使用csv包
读取信息
csvfile = file('csv_test.csv', 'rb')
reader = csv.reader(csvfile)
for line in reader:
print line
csvfile.close()
写信息
csvfile = file('csv_test.csv', 'wb')
writer = csv.writer(csvfile)
writer.writerow(['姓名', '年龄', '电话'])
data = [
('aa', '25', '1234567'),
('bb', '18', '789456')
]
writer.writerows(data)
csvfile.close()
writerow写入一行
writerows写入多行