小编Jac*_* B.的帖子

如何增加 csv 文件的默认列宽,以便在打开文件时所有文本都能正确显示?

我正在尝试编写一个函数,从我的数据库中获取数据,该函数已经正常工作。

这是我在添加实际记录之前的标题代码:

        with open('csv_template.csv', 'a') as template_file:
        #declares the variable template_writer ready for appending
        template_writer = csv.writer(template_file, delimiter=',')
        #appends the column names of the excel table prior to adding the actual physical data
        template_writer.writerow(['Arrangement_ID','Quantity','Cost'])
    #closes the file after appending
    template_file.close()
Run Code Online (Sandbox Code Playgroud)

这是我的记录代码,它包含在 while 循环中,并且是将两个脚本分开的主要原因。

            with open('csv_template.csv', 'a') as template_file:
            #declares the variable template_writer ready for appending
            template_writer = csv.writer(template_file, delimiter=',')
            #appends the data of the current fetched values of the sql statement within the while loop to the csv file
            template_writer.writerow([transactionWordData[0],transactionWordData[1],transactionWordData[2]]) …
Run Code Online (Sandbox Code Playgroud)

python csv format excel

2
推荐指数
1
解决办法
4846
查看次数

标签 统计

csv ×1

excel ×1

format ×1

python ×1