请问
python一个txt文件里,某一行碰到关键词就连带向下复制,直到再碰到关键词或者空行就停止复制到另一个txt要怎么办
######## Pseudocode
with open("file", "r+") as fr:
fr.readlines() # read file
start_row, end_row
copy_str
for line_data in fr.readlines():
if(start_row == "" and line_data.find(key_word)): # get start line
# start_row = line_data
copy_str = copy_str + line_data
continue
if(start_row != ""):
copy_str = copy_str + line_data
if(start_row != "" and end_row == "" and (line_data.find(key_word) || line_data.strip() == "")): # get end line
# end_row = line_data
# copy_str = copy_str + line_data
with open("write_file","r+") as fw:
fw.write(copy_str) # get start_row and end_row, end current copy, initional data
start_row = ""
end_row = ""