1、txt 文件读写 # -*- coding:utf-8 -*- file = open('file.txt','r') # 获取所有的信息 print file.read() print file.write("你好") # 获取所有并且在所有行存在一个数组 print file.readlines() # 获取第一行 print file.readline()
2、# 读取csv文件 # -*- coding:utf-8 -*- import csv writer = csv.writer(open('test.csv','wb')) writer.writerow(['col1','col2','col3']) data = [range(3) for i in range(3)] for item in data: writer.writerow(item) filelist = csv.reader(open('./test.csv','r')) for item in filelist: print item