Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python模式匹配与解析_Python_Loops_Pattern Matching - Fatal编程技术网

Python模式匹配与解析

Python模式匹配与解析,python,loops,pattern-matching,Python,Loops,Pattern Matching,每当事件名称中有匹配项时,我想转储以下信息 1. Event ID 2. Interview ID 一旦事件名称中存在有效匹配项,是否有任何方法来回遍历 具有大约1000个类似结构事件的示例文件内容: Event ID: 17013 Event Component: FIS Event Type: VISA/NOA/CHAP HINT: NORTH Event Creator: soc-cvt **Event Name: Up_MemRd_Unaligned_mburst_ge_0x8** I

每当事件名称中有匹配项时,我想转储以下信息

1. Event ID
2. Interview ID
一旦事件名称中存在有效匹配项,是否有任何方法来回遍历

具有大约1000个类似结构事件的示例文件内容:

Event ID: 17013
Event Component: FIS
Event Type: VISA/NOA/CHAP
HINT: NORTH
Event Creator: soc-cvt
**Event Name: Up_MemRd_Unaligned_mburst_ge_0x8**
InterView ID: 22282
InterView Folder ID: 624
InterView Folder Name: SC_MainFabric_Transactions
Event Priority: 3
Sample Mode: per-seed
Event Conditional: !conditionals
CHAP Counter 0: counter_0,sum,>,10,warn`enter code here`

Event ID: 2324
Event Component: state
Event Type: VISA/NOA/CHAP
.........

1.读取整个事件条目。2.检查事件名称。3.如果匹配,您就拥有所需的所有信息。
eid, iid = -1,-1
search_for='Up_MemRd_Unaligned_mburst_ge_0x8'
with open("input") as f:
    for line in f:
        line = line.rstrip()
        if 'Event ID' in line: eid = line.split(':')[1].strip()
        elif 'InterView ID' in line and name:
            iid = line.split(':')[1].strip()
            print "1.", eid
            print "2.", iid
        elif 'Event Name' in line:
            name = line.split(':')[1].strip(" *")
            if name != search_for: name = ""