我有一个代码,我只想让/X/Y/Z/C,/X/Y/Z/D,/X/Y/Z/E返回(不管在-tree后面是什么)。 它实际上应该读取文件,忽略所有内容,直到看到WFS,然后在{}中获取信息,找到树并返回路径。你知道吗
我是Python的初学者。匹配模式不起作用,因为我认为路径每天都在变化。 任何帮助都将不胜感激。你知道吗
代码:
DEFAULTS
{
FS
{
-A AAA
-B
} -aaaaaa
C
{
}
}
D "FW0"
{
}
WFS "C:" XXXX:"/C"
{
-trees
"/X/Y/Z/C"
"/X/Y/Z/D"
"/X/Y/Z/E"
-A AAA
}
我不确定您的模式的具体变化是什么,但您可以使用正则表达式组:
您可能需要稍微摆弄一下regex,但这里的重点是投入一点时间学习regex,您不必处理其他地方建议的一些不必要的复杂解决方案。Regex是一种小型语言,专门为许多与文本相关的东西而构建,它是非常重要的知识,甚至对于python新手来说也是如此。你会很高兴把时间花进去的!python社区很有帮助,所以为什么不加入IRC,我们将在您最喜欢的python频道中看到您的实时帮助。你知道吗
祝你好运,如果你需要更多帮助,请告诉我。你知道吗
睡衣
我对你的文件的布局有点困惑,但是有什么理由不逐行解析它吗?你知道吗
这不太好,但我想会有用的!让我们试试:
基于状态机的词法分析器可以可靠地完成这一任务。你知道吗
它可以识别我们感兴趣的文件结构:嵌套的花括号、命名的节(一个标识符和一个左大括号在下面的一行;这个只关心顶级节)和子句(在顶级节中由
-identifier
开始,可能后跟数据行,并由另一个子句或节的结尾终止)。你知道吗然后它继续读取文件并打印找到的数据行(如果它们恰好位于我们感兴趣的节和子句中)。它还会在找到它们时设置一个标志,以便在该子句结束后立即退出。你知道吗
在样本上,这个输出 你知道吗
相关问题 更多 >
编程相关推荐