It’s just data
Hm, the test fails:
[blalor@beaker ...ps/Phonebook/data]> python lazydom.py
Traceback (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_'
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 atHere'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 atThanks, 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 atAnother option for this kind of thing is Aaron's xmltramp: http://www.aaronsw.com/2002/xmltramp/
Posted by Nelson atThis 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 atGary: 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:
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
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
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 atHere's the code. Key new features vs the original: element[:] returns all children of all elements in the list element[f] will apply function f to all elements in the list, and act either as a filter or as a map or even...
[more]
Trackback from Sam Ruby