PYTHON:读取Csv文件并将每行(保留页眉)打印/写入htmlfi

2024-09-28 01:22:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我能够生成每行的html文件。在

我当前对“text_file 1.html”的输出是头:['ID', 'Name', 'Type', '3 Year Funds Offered', '3 Year Funds Sold', 'Est. Most Recent Fund Date', 'Investor Location', 'Investor City', 'Investor State', 'Investor Country', 'Portfolio Size', 'Number of Deals', 'Website', 'Average Growth Score']

但我想自定义表/数据,并保留csv中每个数据的标题。

下面是我的示例代码:

import csv

    with open('test.csv', 'r') as csvfile:
           r = csv.reader(csvfile, delimiter=',')
           cnt=0
           for row in r:
               cnt+=1
               file_path="text_file %s.html" % (str(cnt),)
               with open(file_path,"w") as text_file:               
                   text_file.write(str(row)+"\n")`enter code here`

你有什么建议可以让我正确地运行这个程序吗?谢谢!在


Tags: csv数据csvfilepathtexthtmlaswith

热门问题