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

2019-07-18  本文已影响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 替换成空格。

上一篇 下一篇

猜你喜欢

热点阅读