1
如何提取位於文本中間的塊。如何提取位於文件中文本中間的塊
例子:
User authority
--------------
Subscriber number = 189159
Call-out authority = Intra-office
= Local
= Local toll
= National toll
= International toll
= Intra-Centrex
= Outgoing Centrex
= Intra-office national toll
= Intra-office international toll
= Intra-centrex local toll
= Intra-centrex national toll
= Intra-centrex international toll
= Intra-office local toll
= Customize call-out authority 1
= Customize call-out authority 2
= Customize call-out authority 3
= Customize call-out authority 4
= Customize call-out authority 7
= Customize call-out authority 9
= Customize call-out authority 10
= Customize call-out authority 11
= Customize call-out authority 12
= Customize call-out authority 13
= Customize call-out authority 14
= Customize call-out authority 15
= Customize call-out authority 16
Call-in authority = Intra-office
= Local
= Local toll
= National toll
= International toll
= Intra-Centrex
= Incoming Centrex
= Intra-office national toll
= Intra-office international toll
= Intra-centrex local toll
= Intra-centrex national toll
= Intra-centrex international toll
= Intra-office local toll
= Customize call-in authority 1
= Customize call-in authority 2
= Customize call-in authority 3
= Customize call-in authority 4
= Customize call-in authority 5
= Customize call-in authority 6
= Customize call-in authority 7
= Customize call-in authority 8
= Customize call-in authority 9
= Customize call-in authority 10
= Customize call-in authority 11
= Customize call-in authority 12
= Customize call-in authority 13
= Customize call-in authority 14
= Customize call-in authority 15
= Customize call-in authority 16
Call-in Barring Authority = NULL
K value = K0
我只是想提取與呼出權限=局內開始塊直到叩除非管理局= NULL
這是我的代碼:
begin=' Call-out authority ='
end=' Call-in Barring Authority ='
with open("data.txt", "r") as f:
t = f.read()
i = t.find(begin)
j=t.startswith(end)
print(t[i:j])
data.txt是文件。
謝謝大家。