我在 Python 中有这个数组:
['', '/ISk5\\2ME382-1003', '', '0-0:96.1.1(4B414C37303035303932383736393132)', '1-0:1.8.1(00663.661*kWh)', '1-0:1.8.2(00643.213*kWh)', '1-0:2.8.1(00000.036*kWh)', '1-0:2.8.2(00000.028*kWh)', '0-0:96.14.0(0001)', '1-0:1.7.0(0000.12*kW)', '1-0:2.7.0(0000.00*kW)', '0-0:17.0.0(0999.00*kW)', '0-0:96.3.10(1)', '0-0:96.13.1()', '0-0:96.13.0()', '0-1:24.1.0(3)', '0-1:96.1.0(3234313537303032393736363636323132)', '0-1:24.3.0(130713200000)(00)(60)(1)(0-1:24.2.1)(m3)', '(00966.040)', '0-1:24.4.0(1)']
这只是将数据转换为数组(数据略有不同):
/ISk5\2ME382-1003
0-0:96.1.1(4B414C37303035313039)
1-0:1.8.1(00180.724*kWh)
1-0:1.8.2(00001.416*kWh)
1-0:2.8.1(00000.000*kWh)
1-0:2.8.2(00000.000*kWh)
0-0:96.14.0(0001)
1-0:1.7.0(0000.42*kW)
1-0:2.7.0(0000.00*kW)
0-0:17.0.0(0999.00*kW)
0-0:96.3.10(1)
0-0:96.13.1()
0-0:96.13.0()
0-1:24.1.0(3)
0-1:96.1.0(32383031313030313231)
0-1:24.3.0(120911010000)(00)(60)(1)(0-1:24.2.1)(m3)
(00007.646)
0-1:24.4.0(1)
!
现在,我只对某些行感兴趣。我能够提取我想要的所有数据,除了一行。更具体地说,这一行:(00007.646)
此行始终是 0-1:24.3.0(120911010000)(00)(60)(1)(0-1:24.2.1)(m3) 之后的第一行。
换句话说,我希望 python 找到这一行,并给我下一行的输出。
我如何实现这一目标?我的代码:
for line in stack:
if line[0:9] == "1-0:1.8.1":
a = line[10:18]
elif line[0:9] == "1-0:1.8.2":
b = line[10:18]
elif line[0:9] == "1-0:1.7.0":
c = line[10:17]
elif line[0:10] == "0-1:24.3.0":
d = line[+1]
else:
pass