是否可以使用Python中的re2? [英] Is it possible to use re2 from Python?

查看:217
本文介绍了是否可以使用Python中的re2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚发现了 http://code.google.com/p/re2 ,使用长久以来被忽略的方法(汤普森NFA )来实现正则表达式引擎可能比awk,Perl或Python的可用引擎快几个数量级.

i just discovered http://code.google.com/p/re2, a promising library that uses a long-neglected way (Thompson NFA) to implement a regular expression engine that can be orders of magnitudes faster than the available engines of awk, Perl, or Python.

所以我下载了代码并做了通常的sudo make install事情.但是,该动作似乎只不过是在我的系统中添加了/usr/local/include/re2/re2.h而已.似乎有一些``` .a file in addition, but then what is it with this .a``扩展名吗?

so i downloaded the code and did the usual sudo make install thing. however, that action had seemingly done little more than adding /usr/local/include/re2/re2.h to my system. there seemed to be some ```.afile in addition, but then what is it with this.a`` extension?

我想使用Python(最好是Python 3.1)中的re2,很高兴看到发行版中的make_unicode_groups.py之类的文件(也许只是在构建过程中使用了?).但是这些没有部署在我的机器上.

i would like to use re2 from Python (preferrably Python 3.1) and was excited to see files like make_unicode_groups.py in the distro (maybe just used during the build process?). those however were not deployed on my machine.

我如何从Python使用re2?

how can i use re2 from Python?

更新,两个友好的人指出,我可以尝试从源代码构建DLL/* .so文件,然后使用Python的ctypes库访问这些文件.任何人都可以给出有用的指示来做到这一点吗?我在这里几乎一无所知,尤其是第一部分(构建* .so文件).

update two friendly people have pointed out that i could try to build DLLs / *.so files from the sources and then use Python’s ctypes library to access those. can anyone give useful pointers how to do just that? i’m pretty much clueless here, especially with the first part (building the *.so files).

更新(我之前)也已将此问题发布到 re2开发人员小组,直到现在(这是一个很小的小组),直到今天(人数较多) comp.lang.py

update i have also posted this question (earlier) to the re2 developers’ group, without reply till now (it is a small group), and today to the (somewhat more populous) comp.lang.py group [—thread here—]. the hope is that people from various corners can contact each other. my guess is a skilled person can do this in a few hours during their 20% your-free-time-belongs-google-too timeslice; it would tie me for weeks. is there a tool to automatically dumb-down C++ to whatever flavor of C that Python needs to be able to connect? then maybe getting a viable result can be reduced to clever tool chaining.

(大)为什么这么难?认为在2010年,我们仍然无法拥有丰富的软件,只是彼此交谈.这是一个障碍,每当您想使用Python处理一些C代码时,都必须始终取消这些链接位.这需要大量工作,但是只能提供特定于C代码版本和Python版本的扩展模块,因此它可以快速老化.(/rant) 是否有可能(这不应该是一个纯命令行工具,而该工具需要一个单独的进程来运行这样的事情)(例如,如果我有一个re2可执行文件,它可以为输入的数据生成结果,例如subprocess/Popen/communicate())?每次都需要打开一个进程,但是单个进程会连续运行;也许存在包装程序,它们可以妖魔化"这种C代码.

(rant)why is this so difficult? to think that in 2010 we still cannot have our abundant pieces of software just talk to each other. this is such a roadblock that whenever you want to address some C code from Python you must always cruft these linking bits. this requires a lot of work, but only delivers an extension module that is specific to the version of the C code and the version of Python, so it ages fast.(/rant) would it be possible to run such things in separate processes (say if i had an re2 executable that can produce results for data that comes in on, say, subprocess/Popen/communicate())? (this should not be a pure command-line tool that necessitates the opening of a process each time it is needed, but a single processs that runs continuously; maybe there exist wrappers that sort of ‘demonize’ such C code).

推荐答案

David Reiss为re2组合了一个Python包装器.它没有Python re模块的所有功能,但这只是一个开始.可在此处使用: http://github.com/facebook/pyre2 .

David Reiss has put together a Python wrapper for re2. It doesn't have all of the functionality of Python's re module, but it's a start. It's available here: http://github.com/facebook/pyre2.

这篇关于是否可以使用Python中的re2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆