得到一份纯粹的名单pyparsing.ParseResults'

2024-09-28 21:47:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在尝试从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()时一定遗漏了一些重要的东西。在

迪特玛

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

^{pr2}$

Tags: 文件ofthe列表bythattypeargs
2条回答

tokens.args[0].asList是一个函数。tokens.args[0].asList()是对该函数的调用(在self参数之外没有参数)。看来你想知道后一种表达的类型。在

你能试试吗

 print type(tokens.args[0].asList())

相关问题 更多 >