location severity group timestamp description
'0/PM0 major environ 02/07/18 22:50:55 Power Module Output Disabled'
'0/FT1 critical environ 02/07/18 22:50:55 Fan tray is removed from chassis.'
从上面的输出中,我必须得到以location
为键,severity
,group
,timestamp
和description
作为值的字典。< / p>
我无法获得timestamp
和description
,请参阅输出:
{'0/PM0': ['major', 'environ', '22:50:55', 'Power'], '0/FT1': ['critical', 'environ', '22:50:55', 'Fan']}
预期输出:
{'0/PM0': ['major', 'environ', '02/07/18 22:50:55', 'Power Module Output Disabled'], '0/FT1': ['critical', 'environ', '02/07/18 22:50:55', 'Fan tray is removed from chassis']
答案 0 :(得分:0)
这可能会有所帮助:
import re
a = '''location severity group timestamp description
'0/PM0 major environ 02/07/18 22:50:55 Power Module Output Disabled'
'0/FT1 critical environ 02/07/18 22:50:55 Fan tray is removed from chassis.'
'''
d = {}
for i in a.strip().replace("'", "").split("\n")[1:]:
val = re.split("\s\s+",i)
d[val[0]] = val[1:]
print d['0/PM0']
<强>输出:强>
['major', 'environ', '02/07/18 22:50:55', 'Power Module Output Disabled']