zoukankan      html  css  js  c++  java
  • 解决python写入csv文件每两行间 隔一个空行的问题

    像这样。

    这是因为导入的时候,是这样写的:

    with open('book_statics.csv', 'w+') as csvfile:
        writer = csv.writer(csvfile)
        for i in ans:
            writer.writerow(i)

    只要改成wb+,也就是写二进制文件,就好了吗?

    with open('book_statics.csv', 'wb+') as csvfile:
        writer = csv.writer(csvfile)
        for i in ans:
            writer.writerow(i)

     并没有!!!

    报错:TypeError: a bytes-like object is required, not 'str'

    查阅了官方文档,改成如下即可

    with open('book_statics.csv', 'w+', newline='') as csvfile:
        writer = csv.writer(csvfile)
        for i in ans:
            writer.writerow(i)
    

      

    成功解决。

  • 相关阅读:
    POJ3666 Making the Grade[动态规划]
    vector内部的实现1
    win32概述
    stl概述
    C++概要简介
    类的常量成员
    模板
    c11标准
    异常处理
    pak文件的打包和解包
  • 原文地址:https://www.cnblogs.com/AbsolutelyPerfect/p/7860475.html
Copyright © 2011-2022 走看看