Python可以使用csv模块将txt文件转换为csv文件。是一个示例代码:import csv
Python可以使用csv模块将txt文件转换为csv文件。是一个示例代码:
import csv
# Open the input file in read mode and output file in write mode
with open('input.txt', 'r') as read_obj, \
open('output.csv', 'w', newline='') as write_obj:
# Create a csv.reader object from the input file object
csv_reader = csv.reader(read_obj)
# Create a csv.writer object from the output file object
csv_writer = csv.writer(write_obj)
# Read each row of the input csv file as list
for row in csv_reader:
# Write the list to the output file
csv_writer.writerow(row)
本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处
评论列表(4条)