Re: [xml] [PATCH] Add methods for python3 iterator

Ron Angeles schrieb am 18.09.2014 um 09:14:
xmlCoreDepthFirstItertor and xmlCoreBreadthFirstItertor only
implement a python2-compatible iterator interface. The necessary
method names (__next__) have been added. They just passthrough
to the python2 method (next).
 python/ | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/python/ b/python/
index e507e0f..abf0cd4 100644
--- a/python/
+++ b/python/
@@ -530,6 +530,10 @@ class xmlCoreDepthFirstItertor:
         self.parents = []
     def __iter__(self):
         return self
+    # python3 iterator
+    def __next__(self):
+        return
+    # python2 iterator
     def next(self):
         while 1:
             if self.node:

You can write

    __next__ = next

below the "next" method in both cases. No need to go through an indirection
here. I'd even reverse it: change the method definition to "__next__(self)"
and add a "next" alias instead of the above.

Also note that there is a Python package called "lxml" (developed by me)
that wraps libxml2 and libxslt. People tend to prefer it over the bare
Python bindings that come with both libraries.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]