gpt4 book ai didi

python - 从 'pyparsing.ParseResults' 中获取一个纯列表

转载 作者:太空狗 更新时间:2023-10-30 00:33:25 33 4
gpt4 key购买 nike

我目前正在尝试将 pyparsing 的结果作为纯列表获取,以便我可以展平它。我在文档中读到

ParseResults can also be converted to an ordinary list of strings by calling asList(). Note that this will strip the results of any field names that have been defined for any embedded parse elements. (The pprint module is especially good at printing out the nested contents given by asList().)

所以我尝试定义一个 setParseAction 我在 ParseResult 上工作

我得到的是:

>>> print type(tokens.args[0])
<class 'pyparsing.ParseResults'>
>>> print type(tokens.args[0].asList)
<type 'instancemethod'>

但我期待/需要最后一个是列表类型。在此处使用 asList() 时,我一定遗漏了一些重要的东西。

迪特玛

PS:这里是代币实际外观的 MTC:

>>> print tokens.args[0]
['foo1', ['xxx'], ',', 'graphics={', 'bar1', ['xxx,yyy'], ',', 'bar2',
['xxx,yyy'], ',', 'bar3', ['xxx,yyy,', 'zzz=baz', ['xxx,yyy']], '}']

最佳答案

tokens.args[0].asList 是一个函数。 tokens.args[0].asList() 是对该函数的调用(没有超出 self 参数的参数)。看来您想知道后一个表达式的类型。

关于python - 从 'pyparsing.ParseResults' 中获取一个纯列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10534035/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com