Commits

Gael Pasgrimaud committed 0387197

add each / length

Comments (0)

Files changed (2)

pyquery/README.txt

     >>> d('#test').html()
     '<a href="http://python.org">python</a> !...
 
+Doing something for each elements::
+
+    >>> p.each(lambda e: e.addClass('hello2'))
+    [<p#hello.hello2.hello>]
+
 And you can get back the modified html::
 
     >>> print d

pyquery/pyquery.py

         return '[' + (', '.join(r)) + ']'
 
     ##############
+    # Traversing #
+    ##############
+
+    def each(self, func):
+        for e in self:
+            func(self.__class__([e]))
+        return self
+
+    @property
+    def length(self):
+        return len(self)
+
+    ##############
     # Attributes #
     ##############
     def attr(self, name, value=None):