想要分别提取RX,TX计数器。用于以下列方式从string_output?
打印计数器的任何python示例RX_unicast_packets = 2735118
RX_multicast_packets = 703555
TX_unicast_packets = 3983205
TX_multicast_packets = 1916649
RX
2735118 unicast packets 703555 multicast packets 677 broadcast packets
3439365 input packets 3803190483 bytes
1867301 jumbo packets 0 storm suppression bytes
0 runts 0 giants 0 CRC 0 no buffer
0 input error 0 short frame 0 overrun 0 underrun 0 ignored
0 watchdog 0 bad etype drop 0 bad proto drop 0 if down drop
0 input with dribble 291 input discard
15 Rx pause
TX
3983205 unicast packets 1916649 multicast packets 340 broadcast packets
5900194 output packets 3546311266 bytes
1702539 jumbo packets
0 output errors 0 collision 0 deferred 0 late collision
0 lost carrier 0 no carrier 0 babble 0 output discard
0 Tx pause
"
答案 0 :(得分:0)
我相信正则表达式在这里很有价值,我不确定你是否收到上述输出,但我会假设它是一个字符串类型:
解析TX值:
re.findall(r'RX \d+\ ', string) #to get the matching RX values
re.findall(r'TX \d+\ ', string)#to get the matching TX values
RX_unicast_packets = re.search(r'RX (\d+)\ \w+\ \w+\ (\d+)\ ', string).group(1)
如果要匹配特定值,可以使用re.search组
RX_multicast_packets = re.search(r'RX (\d+)\ \w+\ \w+\ (\d+)\ ', string).group(2)
<input type="button" class="sndButton" id="01" value="Sound 01" onclick="OnClickButtonSound()">
<input type="button" class="sndButton" id="02" value="Sound 02" onclick="OnClickButtonSound()">
<input type="button" class="sndButton" id="03" value="Sound 03" onclick="OnClickButtonSound()">
如果您需要任何进一步的帮助,请告诉我,我很乐意为您提供帮助