txt怎么实现每一行句末添加一个句号,谢谢
我的A.txt内容示例:A A A A .
B B B B
C C C
D D
每个字都以一个空格隔开,每一行都是一句,想要在每一行后面补上句号“.",若有则不添加。怎么实现呢 谢谢 with open('test.txt', encoding='utf-8') as f:
txt = f.read()
result = []
for line in txt.split('\n'):
if line[-1] != '.':
result.append(line + '.')
else:
result.append(line)
with open('result.txt', 'w', encoding='utf-8') as f:
for line in result:
f.write(line + '\n') suchocolate 发表于 2021-11-30 08:59
学到了,谢谢哒{:10_287:}
页:
[1]