美文网首页
一次性去除所有换行的方法

一次性去除所有换行的方法

作者: 年画儿 | 来源:发表于2019-07-18 18:51 被阅读0次
# 打开文件
path = '/Users/austin/Desktop/Fireside Chat with Naval Ravikant - New Frontiers 2019.txt'
file = open(path) 
texts = file.readlines() 

# 去除所有/n
newtexts = []
for text in texts:
    text = text[:-1]
#     text = text.replace('\n','')
    newtexts.append(text)
    
# 去除所有''
while '' in newtexts:
    newtexts.remove('')

file.close()

# 写出清理好的字符串
file2 = open('/Users/austin/Desktop/Fireside Chat with Naval Ravikant - New Frontiers 2019-2.txt','w')
for text in newtexts:
    file2.write(text + ' ')
    
file2.close()


word也可以做 https://jingyan.baidu.com/article/2d5afd699529d585a2e28e14.html
command shift +h 进入查找与替换
然后把所有 ^p 替换成空格。

相关文章

网友评论

      本文标题:一次性去除所有换行的方法

      本文链接:https://www.haomeiwen.com/subject/fhjrlctx.html