1.读写CSV数据
import csv
with open('stocks.csv') as f:
f_csv = csv.reader(f)
headers = next(f_csv)
for row in f_csv:
# Process row
...
2.读写JSON数据
import json
json_str = json.dumps(data)
3.解析简单的XML数据
from urllib.request import urlopen
from xml.etree.ElementTree import parse
# Download the RSS feed and parse it
u = urlopen('http://planet.python.org/rss20.xml')
doc = parse(u)
# Extract and output tags of interest
for item in doc.iterfind('channel/item'):
title = item.findtext('title')
date = item.findtext('pubDate')
link = item.findtext('link')
print(title)
print(date)
print(link)
print()
4.增量式解析大型XML文件
8.与关系型数据库的交互
import sqlite3
db = sqlite3.connect('database.db')