Section Menu:  

写csv文件函数:csv_write()

  • 发布时间: 2020-03-31 14:50
  •    阅读: 6329   

描述

        csv_write() csv写入函数
        csv_write() 接收三个参数,第一个参数为输出的文件路径,第二个参数为表头,第三个参数为每行内容


语法

        以下是 csv_write() 的语法:

csv_write(path, headers, rows)

参数

    ● path [str]:文件路径,带csv后缀。
    ●  headers [list]:表头,例:['编号', '课程', '讲师']。
    ●  rows [list]:每行数据,例:[(1, 'Python', 'fighter.Lu'),(2, 'C#', 'fighter.Lu'),(3, '.Net', 'fighter.Lu')]。


返回值

        无返回值


实例

        以下展示了使用 csv_write() 的实例:

from kyger.common import csv_write
headers = ['编号', '课程', '讲师']
rows = [(1, 'Python', 'fighter.Lu'), (2, 'C#', 'fighter.Lu'), (3, '.Net', 'fighter.Lu')]
csv_write('test.csv', headers, rows)

        以上实例运行后输出的结果为:

20200331145832613.png

适应版本

v1.0.1