如何在python中读出以\r\n为结尾(Dos格式)的一行?
3 回答

哔哔one
TA贡献1854条经验 获得超8个赞
s = open('1.txt','r').readlines() #读取成每一行构成的列表
out=open('out.txt','w') #打开一个输出文件用以写入
n=len(s)
for i in range(n):
out.write("%s %s"%(s[i],[i])) #向输出文件中写入:第i行、数字i
out.close()

Smart猫小萌
TA贡献1911条经验 获得超7个赞
1 2 3 4 5 6 | filename="文件名" result=[] for f in open(filename): result.append(f) result[-1]='c'+result[-1] open(filename,'w').writelines(result) |
将文件最后一行前加上字符 c
添加回答
举报
0/150
提交
取消