Python CSV example
#!/usr/bin/python
# -*- coding: utf-8 -*-
import csv
with open('data.csv', 'rb') as f:
reader = csv.reader(f)
for row in reader:
print row
# writing to csv file
with open('data.csv', 'wb') as f:
writer = csv.writer(f)
writer.writerow(['name', 'address', 'age']) # single line
data = [('xiaoming ', 'china', '10'), ('Lily', 'USA', '12')]
writer.writerows(data) # multiple lines
Comments
Post a Comment