1

我有包含以下行的文本文件:

Cycle 0 DUT 2 Bad Block : 2,4,6,7,8,10,12,14,16,18,20,22,24,26,28
Cycle 0 DUT 3 Bad Block : 4,6,8,10,12,14,16,18,20,22,24,26
Cycle 0 DUT 4 Bad Block : 4,6,8,10,12,14,16,18,20,22,24,26
Cycle 1 DUT 2 Bad Block : 2,4,6,7,8,10,12,14,16,18,20,22,24,26,28
Cycle 1 DUT 3 Bad Block : 4,6,8,10,12,14,16,18,20,22,24,26,28,30,32

我想将Cycle 0 DUT 2文本行(冒号后用逗号分隔的Cycle 1 DUT 2数字)与文本行(冒号后用逗号分隔的数字)进行比较并获取差异,然后将Cycle 0 DUT 3文本行与Cycle 1 DUT 3文本行进行比较并获取差异或唯一值。

4

1 回答 1

1

我猜你想把事情DUT写到数字上:

import re
dut_data = {}

cycle_dut = re.compile('^Cycle\s+(\d)\s+DUT\s+(\d)\s+Bad Block\s*:\s*(.*)$')

with open(inputfile, 'r') as infile:
    for line in infile:
        match = cycle_dut.search(line)
        if match:
            cycle, dut, data = match.groups()
            data = [int(v) for v in data.split(',')]
            if cycle == '0':
                # Store cycle 0 DUT values keyed on the DUT number
                dut_data[dut] = data
            else:
                # Compare against cycle 0 data, if the same DUT number was present
                cycle_0_data = dut_data.get(dut)
                if cycle_0_data is not None:
                    # compare cycle_0_data and data here
                    print 'DUT {} differences: {}'.format(dut, ','.join([str(v) for v in sorted(set(cycle_0_data).symmetric_difference(data))]))

我使用快速设置差异来打印差异,这可能需要改进。

对于您的示例数据,将打印:

DUT 2 differences: 
DUT 3 differences: 28,30,32
于 2013-04-10T21:01:40.003 回答