【发布时间】:2018-04-24 19:23:37
【问题描述】:
我从一个文件中读取,如果它找到".",它应该在文本中添加一个换行符"\n" 并将其写回文件。我试过这段代码,但仍然有问题。
inp = open('rawCorpus.txt', 'r')
out = open("testFile.text", "w")
for line in iter(inp):
l = line.split()
if l.endswith(".")
out.write("\n")
s = '\n'.join(l)
print(s)
out.write(str(s))
inp.close()
out.close()
【问题讨论】:
-
问题是什么?
-
我正在读取一个文件,如果它找到一个“。”或句尾,应添加换行符,然后继续拆分。
-
你的文本文件很大吗?还是不行?
-
举个输入输出文件的例子。
-
@TheAfghan:您的输入文本文件只有一行?像 bla.hi.hello.ss.dd 还是多行?
标签: python python-2.7 python-3.x python-requests wxpython