【发布时间】:2015-03-20 06:59:04
【问题描述】:
在从另一个文件写入文件时,是否可以使用 python 跳过文本块?
例如,假设输入文件是:
This is the file I would like to write this line
I would like to skip this line
and this one...
and this one...
and this one...
but I want to write this one
and this one...
我如何编写一个脚本,让我跳过某些内容和大小不同的行,一旦识别到某个行,它就会继续将这些行写入另一个文件?
编辑
我的代码通读行,不写重复行,并使用字典和正则表达式对行执行一些操作。
【问题讨论】:
-
这完全取决于您要跳过这些行的为什么。需要有一些可编码的 rule 来选择某些行而不是其他行。假设你有这个规则,这个程序真的变得非常简单......
标签: python file input output writing