我是新來的python,我正試圖讀取一個文件,並從它創建一個字典。 格式如下:從文件python創建一個字典
.1.3.6.1.4.1.14823.1.1.27 {
TYPE = Switch
VENDOR = Aruba
MODEL = ArubaS3500-48T
CERTIFICATION = CERTIFIED
CONT = Aruba-Switch
HEALTH = ARUBA-Controller
VLAN = Dot1q INSTRUMENTATION:
Card-Fault = ArubaController:DeviceID
CPU/Memory = ArubaController:DeviceID
Environment = ArubaSysExt:DeviceID
Interface-Fault = MIB2
Interface-Performance = MIB2
Port-Fault = MIB2
Port-Performance = MIB2
}
第一行OID(.1.3.6.1.4.1.14823.1.1.27 {)我希望這是鍵和其餘的行是值,直到}
我已經嘗試了幾種組合,但是無法獲得正確的正則表達式來匹配這些
請幫忙嗎?
我已經試過類似
lines = cache.readlines()
for line in lines:
searchObj = re.search(r'(^.\d.*{)(.*)$', line)
if searchObj:
(oid, cert) = searchObj.groups()
results[searchObj(oid)] = ", ".join(line[1:])
print("searchObj.group() : ", searchObj.group(1))
print("searchObj.group(1) : ", searchObj.group(2))
是的,它總是.1.3.6.1.4.x.x.x.x – D2D2