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

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


UYOU
浏览 1168回答 3
3回答

哔哔one

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行、数字iout.close()

Smart猫小萌

123456filename="文件名"result=[]for f in open(filename):    result.append(f)result[-1]='c'+result[-1]open(filename,'w').writelines(result)将文件最后一行前加上字符 c
打开App,查看更多内容
随时随地看视频慕课网APP