我有一个 python 脚本,它的以下输出存储在一个名为 jvmData 的变量中:
Stats name=jvmRuntimeModule, type=jvmRuntimeModule#
{
name=HeapSize, ID=1, description=The total memory (in KBytes) in the Java virtual machine run time., unit=KILOBYTE, type=BoundedRangeStatistic, lowWaterMark=1048576, highWaterMark=1048576, current=1048576, integral=0.0, lowerBound=1048576, upperBound=2097152
name=FreeMemory, ID=2, description=The free memory (in KBytes) in the Java virtual machine run time., unit=KILOBYTE, type=CountStatistic, count=348466
name=UsedMemory, ID=3, description=The amount of used memory (in KBytes) in the Java virtual machine run time., unit=KILOBYTE, type=CountStatistic, count=700109
name=UpTime, ID=4, description=The amount of time (in seconds) that the Java virtual machine has been running., unit=SECOND, type=CountStatistic, count=3706565
name=ProcessCpuUsage, ID=5, description=The CPU Usage (in percent) of the Java virtual machine., unit=N/A, type=CountStatistic, count=0
}
我想做的只是打印出重要部分的名称/值对,在这种情况下,它只是:
HeapSize=1048576
FreeMemory=348466
UsedMemory=700109
UpTime=3706565
ProcessCpuUsage=0
我对python一点也不擅长:)我脑海中唯一的解决方案似乎很啰嗦?拆分行,丢弃第一行,第二行和最后一行,然后以不同的情况(有时是当前的,有时是计数的)循环遍历每一行以查找字符串的长度等
也许(当然)我错过了一些不错的功能,我可以使用这些功能将它们放入等效于 java hashmap 之类的东西中?