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 に答える