buhong 发表于 2018-8-8 12:53:59

python3.x操作csv文件的实战

#引入包  
import csv
  
#打开文件
  
csvfile = open('xiaoqiang.csv', 'w',newline='')
  
#获得对象
  
writer = csv.writer(csvfile)
  
#写入一行数据
  
writer.writerow(('名称', '网址'))
  
#定义要写入多行数据的内容
  
rows= [
  
('小强的博客', 'http://blog.51cto.com/xqtesting'),
  
('小强的视频', 'http://edu.51cto.com/lecturer/4626073.html')
  
]
  
#写入多行
  
writer.writerows(rows)
  
#关闭
  
csvfile.close()
页: [1]
查看完整版本: python3.x操作csv文件的实战