【问题标题】:Create a Multilevel dictionary by reading the provided logfile and output the dictionary通过读取提供的日志文件创建多级字典并输出字典
【发布时间】:2015-06-20 14:05:28
【问题描述】:

需要通过读取提供的日志文件来创建多级字典并将字典输出为

{"Pattern1":{"line1":"Services","line2":"0001","line3":{"include":"BFE"},"line4":{"Include":"1*1"},"line5":"0","line7":{"Include":"2*2"},"line8":{"services":["stop","pause","delete","startup"]}}, "Pattern2":{"line1":"Registry"......}, "Pattern3":{"line1":"Files"......} }

日志文件如下

Pattern1 {
    line1 "Services"
    line2 "0001"
    line3 {Include -e "BFE"}
    line4 {Include "1*1"}
    line5 0
    line6 {Include "2*2"}
    line7 {Include "3*3"}
    line8 "-d" "-c" "services:stop" "services:pause" "services:delete" "services:startup"
}

Pattern2 {
    line1 "Registry"
    line2 "0002"
    line3 0
    line4 { Include -e      "\\REGISTRY\\MACHINE\\*\\ItemData"  }
    line5 { Include "*006f006e00*" }
    line6 { Include "*" }
    line7 { Include "*" }
    line8 "-c" "-d" "registry:modify" "registry:create"
}

Pattern3 {
    line1 Files
    line2 0003
    line3 0
    line4 { Include "$Home\\" }
    line5 { Exclude $n "NT AUTHORITY" "NT System" "AUTHORITY\\ SERVICE"}
    line6 {Include "*"}
    line7 {Include "*"}
    line8 files:read files:create files:write files:delete
}

有人可以帮帮我吗?

【问题讨论】:

  • 你自己有什么想法吗?你有没有厌倦实现它?
  • 某些数据最终出现在列表中而其他数据被忽略并没有真正明显的原因
  • 试一试..应该比寻求答案对你更有帮助..我想,不是吗?

标签: python dictionary multi-level


【解决方案1】:

不精确但不费吹灰之力:

>>> d = {"Pattern1":{"line1":"Services","line2":"0001","line3":{"include":"BFE"},
    "line4":{"Include":"1*1"},"line5":"0","line7":{"Include":"2*2"},"line8":
    {"services":["stop","pause","delete","startup"]}}, "Pattern2":
    {"line1":"Registry"}, "Pattern3":{"line1":"Files"} }
>>> pprint.pprint(d)
{'Pattern1': {'line1': 'Services',
              'line2': '0001',
              'line3': {'include': 'BFE'},
              'line4': {'Include': '1*1'},
              'line5': '0',
              'line7': {'Include': '2*2'},
              'line8': {'services': ['stop', 'pause', 'delete', 'startup']}},
 'Pattern2': {'line1': 'Registry'},
 'Pattern3': {'line1': 'Files'}}

只是为了灵感。

PS:Stackoverflow is not a code-writing service.

【讨论】:

    猜你喜欢
    • 2019-05-05
    • 1970-01-01
    • 2015-10-01
    • 2020-02-06
    • 2013-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多