【发布时间】:2017-05-18 13:24:31
【问题描述】:
我有一个文本文件,test.txt,其中包含以下数据:
content content
more content
content conclusion
==========
content again
more of it
content conclusion
==========
content
content
contend done
==========
我想获得由========== 分隔的块列表。
对于上面的例子,我希望是这样的:
foo = ["content content\more content\content conclusion",
"content again\more of it\content conclusion",
"content\content\contend done"]
另外,如果有人可以分享执行此操作的一般过程(如果有的话),我将不胜感激。
【问题讨论】:
-
你试过了吗?
-
open(...).read().split('==========') -
尝试删除所有
[\r]\ns 并在分隔符处拆分。
标签: python string file python-3.x