我想使用xpath表达式来获取属性的值.
我期望以下工作
from lxml import etree
for customer in etree.parse('file.xml').getroot().findall('BOB'):
print customer.find('./@NAME')
Run Code Online (Sandbox Code Playgroud)
但这会给出一个错误:
Traceback (most recent call last):
File "bob.py", line 22, in <module>
print customer.find('./@ID')
File "lxml.etree.pyx", line 1409, in lxml.etree._Element.find (src/lxml/lxml.etree.c:39972)
File "/usr/local/lib/python2.7/dist-packages/lxml/_elementpath.py", line 272, in find
it = iterfind(elem, path, namespaces)
File "/usr/local/lib/python2.7/dist-packages/lxml/_elementpath.py", line 262, in iterfind
selector = _build_path_iterator(path, namespaces)
File "/usr/local/lib/python2.7/dist-packages/lxml/_elementpath.py", line 246, in _build_path_iterator
selector.append(ops[token[0]](_next, token))
KeyError: '@'
Run Code Online (Sandbox Code Playgroud)
我错在期待这个工作吗?
我正在调查SUDS作为python的SOAP客户端.我想检查指定服务中可用的方法,以及指定方法所需的类型.
目的是生成用户界面,允许用户选择方法,然后以动态生成的形式填写值.
我可以获得有关特定方法的一些信息,但我不确定如何解析它:
client = Client(url)
method = client.sd.service.methods['MyMethod']
Run Code Online (Sandbox Code Playgroud)
我无法编程以 确定我需要创建哪种对象类型才能调用该服务
obj = client.factory.create('?')
res = client.service.MyMethod(obj, soapheaders=authen)
Run Code Online (Sandbox Code Playgroud)
有没有人有一些示例代码?
我正在学习Clojure,我需要在正确的方向上推动我想出的这个问题.
我有一系列事件.每个活动都包含一个"日期".
(def events
[
[1509 :marry "Catherine of Aragon"]
[1527 :unmarry "Catherine of Aragon"]
[1533 :marry "Anne Boleyn"]
[1536 :unmarry "Anne Boleyn"]
[1536 :marry "Jane Seymour"]
[1537 :unmarry "Jane Seymour"]
[1540 :marry "Anne of Cleves"]
[1540 :unmarry "Anne of Cleves"]
[1540 :marry "Catherine Howard"]
[1542 :unmarry "Catherine Howard"]
[1543 :marry "Catherine Parr"]])
Run Code Online (Sandbox Code Playgroud)
我想将其转换为惰性时间轴,即每年包含一个向量的序列.从第一个事件的年份开始,并继续无限.
[[[:marry "Catherine of Aragon"]] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [[:unmarry "Catherine of Aragon"]] [] …Run Code Online (Sandbox Code Playgroud) 我创建了一个实用程序函数来从生成器表达式返回预期的单个项目
print one(name for name in ('bob','fred') if name=='bob')
Run Code Online (Sandbox Code Playgroud)
这是一个很好的方法吗?
def one(g):
try:
val = g.next()
try:
g.next()
except StopIteration:
return val
else:
raise Exception('Too many values')
except StopIteration:
raise Exception('No values')
Run Code Online (Sandbox Code Playgroud)