- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我目前正在尝试将 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/
我正在使用以下类型的 Pyparsing 表达式。 pp.SkipTo(common_cfg)('value 2') + common_cfg + pp.SkipTo(pp.LineEnd()) co
我开发了一个 pyparsing 语法,它必须向输出插入新的标记。此标记不是来自原始输入。 例如: 输入: '/* foo bar*/' 输出: ['comment', '/* foo bar*/']
我正在开发一个翻译器,用于将 PC 上的简单脚本翻译成一些字节码,以便在微 Controller 上执行它(字节码)。 我已经使用 lex 和 re2c 在 C++ 中开发了翻译器,但我正在考虑切换到
是否可以告诉 pyparsing 不存储 ParseResults 或手动丢弃它们? 我正在解析一个大型项目文件,并且可以通过解析操作对每个项目进行所有后处理。因此,一旦一个项目被解析,我就不再需要它
>>> from pyparsing import Word, alphanums, OneOrMore, Optional, Suppress >>> var = Word(alphanums) >
我有一个 ParseResults 对象,当我转储它时它看起来像这样: [[['FM4', '230', '30', '680']]] [0]: [['FM4', '230', '3
我的 PyParsing 语法有以下测试代码: from pyparsing import Word, nums, alphas, delimitedList, Group, oneOf from p
我目前正在尝试将 pyparsing 的结果作为纯列表获取,以便我可以展平它。我在文档中读到 ParseResults can also be converted to an ordinary lis
我觉得在尝试构建生成的解析树(在 pyparsing 中称为 ParseResults)时,ParseActions 使我的代码有点笨拙。 我现在要做的是使用全局变量来存储 Group 元素返回的匹配
我在 Heroku 上运行应用程序时遇到问题。本地版本似乎工作正常,但我无法在 heroku 平台上调用 create_db()。 这是错误轨迹。 (venv)S-MBP:LaunchPage3 S$
我目前正在使用 pyparsing 来识别字符串中是否使用了嵌套括号,以便识别错误地连接到单词的引用号。 例如,“苹果(4)”。 我希望能够识别引用子标记(“(4)”)。但是,当我使用 searchS
有谁知道 Heroku 在部署时有什么变化?我有一个使用 Ubuntu 11.10 的本地开发机器设置,我的项目安装到 venv 中,所有包都通过 pip 管理。相应的requirements.txt
我使用 scala.util.parsing.combinators.Parsers 编写了词法分析器和解析器。我的作品中至少有一个错误,但我有太多错误,很难通过观察它们来确定问题所在。 我需要的是我
非常感谢任何有将 redis 配置为 heroku 上 celery-brokered django 项目后端经验的人的意见。我的任务调度在 localhost 上运行良好,但我发现将它部署到 her
我的测试代码可以在 Python 2.7.11 中运行,但在 Python 3.5.1 中失败: import pyparsing as pp import pickle class Greeting
这里我将第三方库volley转移到retrofit。实际上我在很多项目中都使用了retrofit,但这是一些独特的问题和解决方案,也没有从google得到。 此处应用构建 Gradle: apply
我是一名优秀的程序员,十分优秀!