Lazy DOM
What version of python are you using? Iterator types are new in version 2.2.
On some versions of Redhat, this is installed as python2.
Posted by Sam Ruby atI got the same error and I'm using Python 2.2.2 on Red Hat. I fixed it by changing line 83 to "return iter(result)"
Posted by Simon Willison at
Feedback on lazydom.py
Here's my feedback on the clever lazydom.py. You can use yield to implement __iter__: from __future__ import generators # must be first line of python code ... def __iter__(self): for element in self.list: yield self.new(element) You can use the...Excerpt from gary burd at
Thanks, all, for the feedback. Particularly Gary.
Here's a new version. Tested on Python 2.2 and Python 2.3.
One note: I am definitely trying to maintain the XPath-like abstraction whereby attributes are simply specially named elements. I did, however, add some support to the namespace class to make namespace qualified attributes easier to access.
Posted by Sam Ruby atLook a look at the SF project pywebsvcs; Brian Overhof is doing a great job of adding schema<->python code generation.
Posted by Rich Salz at
Another option for this kind of thing is Aaron's xmltramp: http://www.aaronsw.com/2002/xmltramp/
Posted by Nelson at
This is fun. Python's '/' operator can be used to implement path syntax. If you add this line of code to the lazydom class:
__div__ = __getitem__
then you can write this:
# iteration and traversal
for name in feed/atom.entry/atom.author/atom.name:
print name
print
# attribute access and comparison
print feed/atom.generator/'@name'
print feed/atom.generator/'@name' == 'Blogger'
Egads, Gary, you're evil! And here I thought overloading '+' to mean both numeric addition and string concatenation was bad! :-)
Posted by Ken MacLeod at
Gary: deliciously evil. Playing with it a bit, my one problem is that the precedence order is wrong.
feed/atom.entry[0] will be evaluated as:
- feed/('http://purl.org/atom/ns#','entry')[0]
- feed/'http://purl.org/atom/ns#'
My (initial) conclusion: perhaps div should be considered instead of index, but having both is dangerous.
Posted by Sam Ruby atMore evil. If you add "_floordiv_ = find", then you can write:
for issued in feed.find//atom.issued:
print issued
Java and Web Services are not a match made in heaven
The more I think about this, and read about it, e.g. here, or here, or think about it in this context, the more firmly I believe that Java, or any strongly typed programming language, is a good vehicle for building... [more]Trackback from Random Stuff at
What's with that trackback? I assumed it's autogenerated, but it's
missing a critical "not". Here's from the link target:
"""
The more I think about this, and read about it, e.g. here, or here, or think about it in this context, the more firmly I believe that Java, or any strongly typed programming language, is not a good vehicle for building document-oriented Web services.
"""
Maybe the 1st version of the linked entry was wrong?
Posted by Jean Jordaan at
Hm, the test fails:
[blalor@beaker ...ps/Phonebook/data]> python lazydom.py
Posted by blalor atTraceback (most recent call last):
File "lazydom.py", line 102, in ?
for name in feed[atom.entry][atom.author][atom.name]:
File "lazydom.py", line 83, in _iter_
return result._iter_()
AttributeError: 'list' object has no attribute '_iter_'