Вы можете использовать строку Индекс
Код
def start_stop_dev(lst, dev):
" Assume you meant dev rather than plane "
try:
start_reading = lst.index("--- " + str(dev) + " ---")
except:
return "" # No device
try:
stop_reading = lst.index("--- " + str(dev+1) + " ---") - 1
except:
stop_reading = len(lst)
if start_reading:
return lst[start_reading:stop_reading]
else:
return None # not really possible since return "" earlier
Тест
lst= """=== 169139 ===
Start: 4.80374e+19
End: 4.80374e+19
--- 1 ---
Pix 9, 66
--- 2 ---
Pix 11, 31
Pix 12, 31
--- 3 ---
Pix 17, 53
Pix 16, 53
Pix 16, 54
--- 4 ---
Pix 44, 64
--- 5 ---
Pix 49, 133
Pix 48, 133
--- 6 ---
Pix 109, 143
Pix 108, 143
Pix 108, 144
Pix 109, 144"""
# Retrieve and print data for each device
print('----------------Individual Device String Info-------------')
for dev in range(7):
print(f'device {dev}\n{start_stop_dev(lst, dev)}')
print('----------------Splits of String Info----------------------')
for dev in range(7):
dev_lst = start_stop_dev(lst,dev).split("\n")
print(f'dev {dev}: {dev_lst}')
Вывод ---------------- Информация об отдельных строках устройства -------------
device 0
device 1
--- 1 ---
Pix 9, 66
device 2
--- 2 ---
Pix 11, 31
Pix 12, 31
device 3
--- 3 ---
Pix 17, 53
Pix 16, 53
Pix 16, 54
device 4
--- 4 ---
Pix 44, 64
device 5
--- 5 ---
Pix 49, 133
Pix 48, 133
device 6
--- 6 ---
Pix 109, 143
Pix 108, 143
Pix 108, 144
Pix 109, 144
----------------Splits of String Info----------------------
dev 0: ['']
dev 1: ['--- 1 ---', 'Pix 9, 66']
dev 2: ['--- 2 ---', 'Pix 11, 31', 'Pix 12, 31']
dev 3: ['--- 3 ---', 'Pix 17, 53', 'Pix 16, 53', 'Pix 16, 54']
dev 4: ['--- 4 ---', 'Pix 44, 64']
dev 5: ['--- 5 ---', 'Pix 49, 133', 'Pix 48, 133']
dev 6: ['--- 6 ---', 'Pix 109, 143', 'Pix 108, 143', 'Pix 108, 144 ', 'Pix 109, 144']