首页 > 编程语言 > 详细

Python读取csv文件

时间:2019-12-28 16:18:39      阅读:81      评论:0      收藏:0      [点我收藏+]

创建一个csv文件,命名为data.csv,文本内容如下:

root,123456,login successfully
root,wrong,wrong password
wrong,123456,nonexistent username
,123456,username is null
root,,password is null

使用Excel打开如图:

技术分享图片

利用Python内置的csv读取内容:

import csv

with open('data.csv', 'r', encoding='utf-8')as f:

    reader = csv.reader(f)

    for i in reader:
        print(i)

输出结果:

['root', '123456', 'login successfully']
['root', 'wrong', 'wrong password']
['wrong', '123456', 'nonexistent username']
['', '123456', 'username is null']
['root', '', 'password is null']

Python读取csv文件

原文:https://www.cnblogs.com/milesma/p/12111751.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!