我有这个字符串:
"{'osFreeMem': 286494720, 'osUpTime': 19230718, 'sysload': [0.24609375, 0.62109375, 0.734375], 'nodeUpTime': 1831, 'osTotMem': 536870912, 'nodeMemory': {'heapTotal': 8766304, 'heapUsed': 7789588, 'rss': 22773760}}"
我想要一本具有这些值的字典:
'osFreeMem': 286494720
'osUpTime': 19230718
'sysload': [0.24609375, 0.62109375, 0.734375]
'nodeUpTime': 1831
'osTotMem': 536870912
'nodeMemory': {'heapTotal': 8766304, 'heapUsed': 7789588, 'rss': 22773760}
我如何获得此清单?
最佳答案
您还可以使用内置函数eval
>>>d = eval("{'osFreeMem': 286494720, 'osUpTime': 19230718, 'sysload': [0.24609375, 0.62109375, 0.734375], 'nodeUpTime': 1831, 'osTotMem': 536870912, 'nodeMemory': {'heapTotal': 8766304, 'heapUsed': 7789588, 'rss': 22773760}}")
>>>d
{'osFreeMem': 286494720, 'osUpTime': 19230718, 'sysload': [0.24609375, 0.62109375, 0.734375], nodeUpTime': 1831, 'osTotMem': 536870912, 'nodeMemory': {'heapTotal': 8766304, 'heapUsed': 7789588, 'rss': 22773760}}