试图在Python3.4上构建lxml:系统确实有libxml2和libxslt.
pip build无法确定MULTICORE(?)等等(?)
下载相关版本:
首先,尝试标准构建(动态):
$ CFLAGS="-O0" pip3 install lxml
Run Code Online (Sandbox Code Playgroud)
构建没有错误,但是:
Python 3.4.2 (default, Dec 13 2014, 16:48:48)
[GCC 4.8.3] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> from lxml import etree
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: ld.so.1: isapython3.4: fatal: relocation error: file /usr/lib/python3.4/site-packages/lxml/etree.cpython-34m.so: symbol __xmlStructuredErrorContext: referenced symbol not found
Run Code Online (Sandbox Code Playgroud)
但符号存在:
$ nm /usr/lib/python3.4/site-packages/lxml/etree.cpython-34m.so | grep __xmlStructuredErrorContext
U __xmlStructuredErrorContext
Run Code Online (Sandbox Code Playgroud)
但是在底层libxml2中是'local':
# nm /usr/lib/libxml2.so.2 | grep …
Run Code Online (Sandbox Code Playgroud) 我正在使用Python(实际上是pl/python)在一个非常大的文本对象中连续查找一系列正则表达式匹配.这工作正常!每个匹配都是不同的结果,每个替换将是不同的结果,最终基于循环内的查询.
目前,我很乐意用任何文本替换rx中的每个匹配,这样我就能理解它是如何工作的.有人能给我一个替换匹配文本的明确例子吗?
match.group(1)似乎正确表示匹配的文本; 这是做事的方式吗?
plan3 = plpy.prepare("SELECT field1,field2 FROM sometable WHERE indexfield = $1",
[ "text" ])
rx = re.finditer('LEFT[A-Z,a-z,:]+RIGHT)', data)
# above does find my n matches...
# ------------------- THE LOOP ----------------------------------
for match in rx:
# below does find the 6 match objects - good!
# match.group does return the text
plpy.notice("-- MATCH: ", match.group(1))
# must pull out a substring as the 'key' to an SQL find (a separate problem)
# (not sure how …
Run Code Online (Sandbox Code Playgroud) 使用Python3,希望os.walk
文件目录,将它们读入二进制对象(字符串?)并对它们进行进一步处理.不过第一步:如何读取文件的结果os.walk
?
# NOTE: Execute with python3.2.2
import os
import sys
path = "/home/user/my-files"
count = 0
successcount = 0
errorcount = 0
i = 0
#for directory in dirs
for (root, dirs, files) in os.walk(path):
# print (path)
print (dirs)
#print (files)
for file in files:
base, ext = os.path.splitext(file)
fullpath = os.path.join(root, file)
# Read the file into binary? --------
input = open(fullpath, "r")
content = input.read()
length = len(content)
count += 1
print (" …
Run Code Online (Sandbox Code Playgroud)