【发布时间】:2018-09-16 11:40:56
【问题描述】:
我有这棵树:
Active Mode
|___ Local (EU)
| |___ <Random String>
|___ International (WW)
| |___ <Random String> (I want this random string!!!)
Passive Mode
|___ Local (EU)
| |___ <Random String>
|___ International (WW)
|___ <Random String>
但由于环境原因,我的 python 会将其视为扁平字符串:
Active Mode
Local (EU)
<Random String>
International (WW)
<Random String> (I want this random string!!!)
Passive Mode
Local (EU)
<Random String>
International (WW)
<Random String>
注意:基本上是一个我不知道是什么的随机字符串。
现在很容易得到我想要的线路,我只需要string.split(\n)[4]。棘手的部分是:
- 父母(
Active Mode和Passive Mode)可以改组,所以Active Mode将在 之后Passive Mode - 孩子(
Local (EU)和International (WW))也可以洗牌 - 可能缺少父母或缺少孩子(因此有可能没有
Active Mode,这意味着我应该得到类似None
我想到的一个可能的解决方案是以某种方式将 flat string 转换为多层字典、列表或 json,但我不知道该怎么做。
【问题讨论】:
-
你能有你想要的线路而不是国际(WW)线路吗?
-
我不明白你的意思。如果您问“国际(WW)”线是否是我可以控制的线,那么不是。 “Active Mode”、“Passive Mode”、“International (WW)”和“Local (EU)”是不会改变的预定义变量。然而,他们的顺序或他们的存在可能会有所不同。其他行是一些我不知道的变量。 (希望我说得通)
-
我在问这样的问题:Active Mode Local (EU) I don't want this line I want this line
标签: python json string tree format