# open file for reading
with open('file.txt') as fr:
# get the text in the file
text = fr.read()
# split up the file into lines based on '.'
lines = text.split('.')
# open the file for writing
with open('file.txt', 'w') as fw:
# loop over each line
for line in lines:
# remove leading whitespace, and write to the file with a newline
fw.write(line.lstrip() + '\n')
这就足够了:
您可以根据
.
将字符串split存储在一个列表中,然后打印出该列表。在如果您这样做,输出将是:
^{pr2}$要删除前导空格,可以基于} 。在
.
(带空格)拆分,或者在打印时使用^{因此,要对文件执行此操作:
相关问题 更多 >
编程相关推荐