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

How to fix Google Apps Script: Script function not found: doGet

Selenium supports Java

Creating sort index in MySQL