python语言--------csv模块将txt文件转换为表格csv格式(常用、掌握)
上代码:
import csv
csvFile = open("C:/Users/Administrator/Desktop/1.csv", 'w', newline='', encoding='utf-8')
writer = csv.writer(csvFile)
csvRow = []
f = open("C:/Users/Administrator/Desktop/np.txt", 'r', encoding='GB2312')
for line in f:
csvRow = line.split()
writer.writerow(csvRow)
f.close()
csvFile.close()
实现效果如下: