python之解析csv

使用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写入多行

posted @ 2017-06-09 15:53  hellowcf  阅读(227)  评论(0编辑  收藏  举报