paython3-练习

在文本每行末尾加;

f = open(r'D:	est11.txt','rb')
w = open(r'D:	est12.txt','wb')

for line in f.readlines():
         w.writelines(line.replace('
',';
'))
w.close()

 更好的写法

f = open(r'D:	est11.txt','rb')
w = open(r'D:	est12.txt','wb')
import os
with f as lines:
    with w as outfile:
        for line in lines:
            line = '"' + line.replace(os.linesep, "") + '",' + os.linesep
            outfile.write(line)
View Code
类似写法
f = open(r'D:	est11.txt','rb')
w = open(r'D: est12.txt','wb')

for line in f.readlines():
line = '"'+ line.replace(' ',"") + '"; '
w.writelines(line)
f.close()
w.close()
原文地址:https://www.cnblogs.com/yspass/p/6637551.html