import csv
with open('120301.csv', 'w', newline='') as file:
writer = csv.writer(file)
for line in open('120301.KAP'):
rec = line.strip()
if rec.startswith('PLY'):
writer.writerow(rec.split(','))
target = open(filename, 'w')
for line in open('120301.KAP'):
rec = line.strip()
if rec.startswith('PLY'):
print line
target.write(line)
target.write("\n") #writes a new line
您可以使用csv模块
以类似的方式,
csv.reader
可以轻松地从输入文件中读取记录。 https://docs.python.org/3/library/csv.html?highlight=csv#module-contents在python 2.x中,应该以二进制模式打开文件:
^{pr2}$这是完全可行的!以下是一些文档的链接:https://docs.python.org/2/library/csv.html},用于编写/读取CSV。 你也可以用常规的文件读/写功能制作自己的CSV。在
我想那应该行得通。在
您可以在代码的开头打开文件,然后在打印行后面添加write语句。像这样:
相关问题 更多 >
编程相关推荐