📜  python 将 dat 文件转换为 csv - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:25.980000             🧑  作者: Mango

代码示例3
import csv

with open("04122020_MCDXUV500REFBS4_01.dat") as infile, open("outfile.csv", "w") as outfile:
    csv_writer = csv.writer(outfile)
    prev = ''
    csv_writer.writerow(['ID', 'PARENT_ID'])
    for line in infile.read().splitlines():
        csv_writer.writerow([line, prev])
        prev = line