我正在尝试使用pyparsing解析日志文件。日志文件条目的结构如下:
information line 1
information line 2
...
information line n
attribute name 1 = attribute value 1
attribute name 2 = attribute value 2
...
attribute name n = attribute value n
我编写了这个语法来解析这段文本:
NL = Suppress(LineEnd())
infoline = OneOrMore(Word(alphas + ".-"
我使用下面的代码使用pyparsing在python中解析服务器日志,结果抛出了一个异常。看起来语法是正确的,因为它适用于一行日志,但是为什么我看到这个异常?感谢您的指点或指导!
#!/bin/python
# import required modules
# (include the ones used later after defining grammar)
import string
from pyparsing import alphas, nums, Combine, Word, Group,
delimitedList, Suppress, removeQuotes, al
我从源代码中安装了带有ubuntu 14.04的所有依赖项的matplotlib
Processing dependencies for matplotlib==1.3.1
Searching for nose==1.3.3
Best match: nose 1.3.3
Processing nose-1.3.3-py2.7.egg
Removing nose 1.3.1 from easy-install.pth file
nose 1.3.3 is already the active version in easy-install.pth
Installing nosetests scr
我有一份姓名和年龄的档案,
john 25
bob 30
john bob 35
这是我到目前为止所掌握的
from pyparsing import *
data = '''
john 25
bob 30
john bob 35
'''
name = Word(alphas + Optional(' ') + alphas)
rowData = Group(name +
Suppress(White(" ")) +
我正在尝试为创建一个解析器,然而,当试图在RCSadmin上下文中解析RCSid时,它遇到了无限循环。删除有问题的行
Group(ZeroOrMore(RCSid)).setResultsName('access') + \
导致不发生挂起。RCSid在其上成功解析字符串。有什么建议吗?
这就是我所拥有的:
from pyparsing import *
import string
# Special characters in the RCS file format
special = '$,.:;@'
RCSdigit = Word(
我试图在我的Windows机器上编译machine,但得到了以下错误:
python setup.py build_ext --inplace
running build_ext
cythoning pyparsing.pyx to pyparsing.c
Error compiling Cython file:
------------------------------------------------------------
...
If C{include} is set to true, the matched expression is also parsed (
我在使用pyparsing时遇到了一些基本问题。下面是测试程序和运行的输出。
aaron-mac:sql aaron$ more s.py
from pyparsing import *
n = Word(alphanums)
a = Group( n | Group( n + OneOrMore( Suppress(",") + n )))
p = Group( a + Suppress(".") )
print a.parseString("first")
print a.parseString("first,second"
我正在运行一个需要pydot和graphviz的代码。我使用python3.5和ubuntu16.04LTS 64位。
File "/usr/local/lib/python3.5/dist-packages/keras/utils/vis_utils.py", line 17, in _check_pydot
raise ImportError('Failed to import pydot. You must install pydot'
ImportError: Failed to import pydot. You must install
最近我一直在尝试开发一种自定义编程语言。但是,在我(试图)创建的前面语言以分号结尾的地方,我现在制作的语言是用换行符结束的,就像Python一样。
我偶然发现的问题是,虽然在例如C++中的每一个分号都被视为某种类型的终止符,但Python中的换行符并不总是充当终止符。
例如:
// incorrect in c++
myfunc();;;;otherfunc();
和
# completely fine in python
myfunc()
otherfunc()
所以我的问题是,我如何解析这个?这种语言的巴库斯-诺尔形式是什么样子的?
在标记复制之前,请完整地阅读它。
我正试图在脚本中使用pydot,这依赖于pyparing模块。但是我拥有的模块是pyparation2.0.1,这是与MAC安装一起提供的。需要将其降级为1.5.7以修复此错误--“无法导入dot_parser,按的规定加载点文件是不可能的”,但是当我试图卸载现有的pyparing模块时,我得到了这个错误-
pip uninstall pyparsing
DEPRECATION: Uninstalling a distutils installed project (pyparsing) has been deprecated and will be remo
我正在尝试使用py解译来匹配一个多行字符串,它可以以类似于python的方式继续下去:
Test = "This is a long " \
"string"
我找不到一种方法可以让pyparsing识别出这一点。以下是我迄今尝试过的:
import pyparsing as pp
src1 = '''
Test("This is a long string")
'''
src2 = '''
Test("This is a long " \
我过去曾使用过pyparsing,但只用于小任务,这一次我尝试将其用于更复杂的任务。
我试图跳过一个VHDL体系结构块,它如下所示
architecture Behav of Counter is
...many statements I'm not interested in at this point...
end architecture;
以下是我尝试过的:
import pyparsing as pp
pp_identifier = pp.Regex(r'([a-zA-Z_][\w]*)')('identifier')
def Keywor
我们有一个旧的应用程序,需要迁移到AWS中的新框架。在旧的应用程序中,我们以前有一些基于表达式的语法,用于识别客户端的权限、过期日期等。
我试图在新的语法中转换旧的语法,这是逗号分隔的语法。
我正试图使用pyparsing库来实现这一点,但我觉得我在这里遇到了麻烦。到目前为止,下面的代码给出了旧代码的list分解,但是当旧代码中有嵌套循环时,我无法解析它。
旧码
If (LAST_RUN_DATE>=dat('JUL 01, 90'))
If (pos(con('*',SUB_CODE,'*'),'*ABC*DEF*ASD*