Изменили код, чтобы дать правильный ответ
import re
data = ['- TEST BEGA','R8=11K(10,15A)B','R9=1K(0,3A)B','R10_R84=13MEG(7,14K)R'
,'R85_R84<100K(970,1000K)R','R85_R85=10K(9,11K)R', 'R92_R86=10K(9,12K)R']
last_s = last_c = last_op = last_mc = None
repeat = 0
for i, line in enumerate(data):
if i == 0:
print("SCN:", line.strip("- "))
elif i == 1:
last_s, last_c, last_op, last_mc = re.match("^\s*([^_]+)(_\w+)?([<>=])(.*)\s*$", line).groups()
#last_c = str(last_c)[1:] if last_c != None else last_c
elif line.strip():
s, c, op, mc = re.match("^\s*([^_]+)(_\w+)?([<>=])(.*)\s*$", line).groups()
#print(s, c, op, mc)
#print(last_s, last_c, last_op, last_mc)
if s != last_s:
if repeat > 0:
print("CHILD", last_c or last_s)
print("Operator",op)
print("MEASURE_CHILD", mc)
else:
print("")
print("STEP", ("" + last_s + last_c if last_c != None else last_s))
print("CHILD", ("" + last_s + last_c if last_c != None else last_s))
print("Operator",last_op)
print("MEASURE_CHILD", last_mc)
last_s = s
last_c = c
last_op = op
last_mc = mc
repeat = 0
else:
if repeat == 0:
print("")
print("STEP", last_s )
print("CHILD", str(last_c)[1:] if last_c != None else last_c or last_s)
print("Operator",op)
print("MEASURE_CHILD", mc)
last_s = s
last_c = str(c)[1:] if c != None else c
last_op = op
last_mc = mc
repeat += 1
if repeat == 0:
print("")
print("STEP", ("" + last_s + last_c if last_c != None else last_s))
print("CHILD", ("" + last_s + last_c if last_c != None else last_s))
print("Operator",last_op)
print("MEASURE_CHILD", last_mc)
else:
print("CHILD", str(last_c)[1:] if last_c != None else last_c or last_s)
print("Operator",op)
print("MEASURE_CHILD", mc)
OutPut:
SCN: TEST BEGA
STEP R8
CHILD R8
Operator =
MEASURE_CHILD 11K(10,15A)B
STEP R9
CHILD R9
Operator =
MEASURE_CHILD 1K(0,3A)B
STEP R10_R84
CHILD R10_R84
Operator =
MEASURE_CHILD 13MEG(7,14K)R
STEP R85
CHILD R84
Operator =
MEASURE_CHILD 10K(9,11K)R
CHILD R85
Operator =
MEASURE_CHILD 10K(9,12K)R
STEP R92_R86
CHILD R92_R86
Operator =
MEASURE_CHILD 10K(9,12K)R