使用python 3.5将多个print语句导出到csv

时间:2018-01-30 12:14:38

标签: python-3.5 export-to-csv

我有csv文件有两列,我想将其导出为我想要的格式。到目前为止,我能够将其打印到shell中,我很惊讶将其导出到csv文件中。下面是我尝试过的代码。

import csv
with open('file.csv','r') as csv_file:
    csv_reader = csv.reader(csv_file)

    next(csv_reader)
    sku = 0
    with open('newfile.csv','w') as new_file:
        csv_writer = csv.writer(new_file)

        for i in csv_reader:
            sku = sku + 1
            csv_writer.writerow(i)
            print("message:: {")
            print("  Message ID    :",sku)
            print("  sku           :", i)

任何帮助或指针都会有所帮助。谢谢

0 个答案:

没有答案