[issue21028] ElementTree objects should support all the same methods as Element objects

Raymond Hettinger report at bugs.python.org
Wed Apr 2 09:22:19 CEST 2014


Raymond Hettinger added the comment:

> ElementTree class currently supports that, 
> using the find*() or iter() methods. 

That would be great except that ElementTree doesn't actually have an __iter__ method.

> Ok, but why?

The short answer is that every time I conduct Python training, people routinely trip over this issue.  The whole point of the ElementTree package was to have a more pythonic interface than DOM or SAX.  I'm sure there are people that argue that the requests module isn't great because it conflates requesting with authentication and password management, but the beauty of requests is that its API matches how people try to use it.  The outer ElementTree object is awkward in this regard.

I don't see any benefit from having this code fail:


    from xml.etree.ElementTree import parse

    catalog = parse('books.xml')
    for book in catalog:
        print book.get('id')

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21028>
_______________________________________


More information about the Python-bugs-list mailing list