我有一棵树:
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
的东西)我想到的一个可能的解决方案是以某种方式将扁平字符串转换成多层字典、列表或json,但我不知道该怎么做
我草拟了一些代码,但可能会很危险,因为通常无法保证模式中的随机字符串不会与标题和/或模式名冲突:
parse()
函数的思想是跟踪局部变量mode
和options
中的当前模式。同时,它在out
中维护一个完整的结果对象相关问题 更多 >
编程相关推荐