python中如何把一段文字中的空格替换成换行符

 

1.python中如何把一段文字中的空格替换成换行符

 

def delblankline(infile, outfile):
    infopen = open(infile, 'r', encoding="utf-8")
    outfopen = open(outfile, 'w', encoding="utf-8")
    db = infopen.read()
    outfopen.write(db.replace(' ', '\n'))
    infopen.close()
    outfopen.close()


delblankline(r'ces\D1.txt', r'ces\1.txt')

 

亲测有效

 

 

原文参考:https://www.jb51.net/article/136706.htm

posted @ 2020-12-03 18:18  learn_py_test  阅读(1710)  评论(0)    收藏  举报