我有一个这样的文本文件:-
-----Starting Step for step1-----
text1
text2
text3
-----Ending Step for step1-----
-----Starting Step for step2-----
text4
text5
text6
-----Starting Step for step3-----
text7
text8
text9
-----Ending Step for step3-----
text10
text11
text12
-----Ending Step for step2-----
打开日志文件后,我一直在尝试搜索模式开始步骤和相应的内容。
我将它保存在变量值中,现在如果我在获得模式结束步骤之前获得另一个起始步骤模式,我认为它是早期父母的孩子。
with open('C:\Python27\sample.log','r') as f:
with tag('html'):
with tag('body'):
with tag('pre'):
for line in f:
value=re.findall(r'Starting Step for (\w+)',line)
new_value=re.findall(r'Ending Step for (\w+)',line)
if value not in parent_tag_stop and value not in parent_tag_start:
if parent_tag_start:
parent_tag_start.append(value)
else:
child_tag[parent_tag_start[-1]] =value
elif new_value:
parent_tag_stop.append(value)
if tag==new_value[0]:
with tag('a', href='#{0}'.format(new_value)):
text(value)
value=''
else:
value+=line
我想将每个块从开始步骤拆分到结束步骤,并创建一个 html 页面,其中步骤 1、步骤 2 等作为锚标记,相应的内容作为其文本,这里的步骤 3 将是步骤 2 下的子锚,其内容将是步骤 2 的一部分还