zoukankan      html  css  js  c++  java
  • python读取文件报错:pandas.errors.ParserError: iterator should return strings, not bytes (did you open the file in text mode?)

    python 读取csv文件报错问题

    import csv

    with open('E:/Selenium2script/DDT模块/test.csv','rb') as f:
    readers = csv.reader(f)
    next(readers,None)
    for line in readers:
    print(line)

    输出:
    _csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)


    问题分析:因为此csv文件是一个文本文件,并非二进制文件。

    解决:

    import csv

    with open('E:/Selenium2script/DDT模块/test.csv','rt') as f:
    readers = csv.reader(f)
    next(readers,None)
    for line in readers:
    print(line)
    或者‘rt’换成‘r’
    ————————————————
    版权声明:本文为CSDN博主「海-最强的男人」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/c910118/article/details/78629153

  • 相关阅读:
    CodeForces
    hdu4003 树形dp
    hdu2196
    poj2486
    hdu1502 树形dp入门题
    cf 686D
    bzoj2763 分层图
    hdu4424 并查集+贪心+思维
    poj1734 最小环+输出路径
    集训题解1
  • 原文地址:https://www.cnblogs.com/houfei/p/11693835.html
Copyright © 2011-2022 走看看