【发布时间】:2020-04-21 07:23:58
【问题描述】:
我需要您的帮助来解决以下问题。例如,我有一些大文本文件:
This is the Name of the Person This is his surname He likes to sing every time.
我只想将He likes to sing 与every time. 合并,因为在此之后我对每个字符串执行其他正则表达式。
所以输出应该是:
This is the Name of the Person This is his surname He likes to sing every time.
所以我试过了:
for file in file_list:
with open(file, 'r', encoding='UTF-8', errors='ignore') as f_in:
for line in f_in:
if not line.startswith('\n'):
line.replace('\n', '')
print(line)
感谢您的帮助。
【问题讨论】:
-
print()默认会在行尾添加换行符。试试print(line, end="")