Digital Marketing

Python CSV example

# -*- 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


Popular posts from this blog

Fixed WSL sshd: no hostkeys available -- exiting

PowerMTA pmta command

How to fix: mv: failed to preserve ownership