

步骤1:读取每行(每行的类型是str)
步骤2:对每行列表化
步骤3:弹出每行的/n两个字符
步骤4:追加,/n三个字符
代码实现如下:
#import os
From_file=open('D:\python\A\tianqi.txt')
f=open('niuniu1.txt','w')
count=0
huancun=[]
for each_line in From_file:
#print(type(each_line)) each_line 是字符类型
Delstr=list(each_line)
Delstr.pop() #弹出n
Delstr.pop() #弹出
Delstr.append(',
')
huancun="".join(Delstr)
print(huancun)
f.writelines(huancun)
count+=1
huancun=[]
f.close()
From_file.close()
print('文件中总共有:%d行'%count)