我是新的Python。我有一个简单的任务,将特定的文本文件行写入另一个文本文件。文本文件的格式是这样将文本文件的特定行写入文本文件 - Python
.A
some text1 -- skip
some text2 -- skip
.B
.some text3 -- write
.some text4 -- write
我需要跳过.A和.B,当我遇到.B开始从一些text3..etc的新文件写入数据之间的数据。
我使用Python 2.7
我想这一点 -
with open("Myfile.txt","r") as myfile:
for line in myfile:
if line.startswith(".A"):
writefile = open("writefile.txt", "a")
else:
if not (line.startswith(".B")):
continue
else:
writefile.write(line)
我想在别的块我搞砸了的东西..
您有什么问题? – saulspatz
请分享你到目前为止所尝试过的 – csharpcoder