正在尝试替换"&引用;使用python中的新行(\n),在“";之后没有空格”&引用;

正在尝试替换"&引用;使用python中的新行(\n),在“";之后没有空格”&引用;,python,replace,newline,strip,Python,Replace,Newline,Strip,我试图用python中的新行(“\n”)替换“.” input file: abc. abc def. def new input: Nigel Reuben Rook Williams (15 July 1944 – 21 April 1992) was an English conservator and expert on the restoration of ceramics and glass. From 1961 until his death he worked at the B

我试图用python中的新行(“\n”)替换“.”

input file:
abc. abc
def. def

new input:
Nigel Reuben Rook Williams (15 July 1944 – 21 April 1992) was an English conservator and expert on the restoration of ceramics and glass. From 1961 until his death he worked at the British Museum, where he became the Chief  successful restorations of the Sutton Hoo helmet and the Portland Vase.

Joining
代码:

我想删除新行之前的空格

expected new output:
nigel reuben rook williams july april was an english  restoration of ceramics and glass
from until his death he worked at the british museum where he became the 
chief conservator of ceramics and glass in
there his work included the successful restorations of the sutton hoo helmet 
and the portland vase
joining

点后有空格。您可以使用
line.replace('.','\n')

或者您可以使用:

for line in test_file:
    words = line.split('.')
    for word in words:
        test_file_1.write(word.strip()+'\n')

line.replace('.','\n')
-\u@OlvinRoght 2更多问题:1-我在文本文件中有一行,例如:“hello.world lala.”第一行“replace起作用,第二行“在行尾它不起作用”。2-我还想删除两条线之间的间隙。例如“abc”,然后是新行和1行的间隔(我想删除),您能在您的问题中提供真实的输入/输出吗?当然,看看新的输入。@OlvinRoght当然,看看新的输入。但是<代码>行.拆分('.')
for line in test_file:
    words = line.split('.')
    for word in words:
        test_file_1.write(word.strip()+'\n')