[docs] (correction)Bug in ETree

Noonan noonanes at gmail.com
Wed Jun 17 18:10:15 CEST 2015


>From what I see, it's working fine for you, but I'm running an older
version of Python. THis version of python is shipped with the VHDs my
company packages for maintenance. Do you know if this was fixed since
October?

On Wed, Jun 17, 2015 at 6:10 AM, Senthil Kumaran <senthil at uthcode.com>
wrote:

> Hello Noonan,
>
> In general, I agree that docs could see improvement in listing examples.
>
> Specifically what was the bug in ET object’s .findall or .find ?
>
> Here I use the example listed in the docs and works fine for me.
>
> $ ./python.exe
> Python 3.4.3+ (3.4:3ded282f9615, Jun 17 2015, 06:05:20)
> [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import xml.etree.ElementTree as ET
> >>> tree = ET.parse('country_data.xml')
> >>> root = tree.getroot()
> >>> root.findall(".")
> [<Element 'data' at 0x10ea87b88>]
> >>> root.findall("./country/neighbor")
> [<Element 'neighbor' at 0x10eb63868>, <Element 'neighbor' at 0x10eb638b8>,
> <Element 'neighbor' at 0x10eb63a48>, <Element 'neighbor' at 0x10eb63bd8>,
> <Element 'neighbor' at 0x10eb63c28>]
> >>> root.findall(".//year/..[@name='Singapore']")
> [<Element 'country' at 0x10eb63908>]
> >>> root.findall(".//*[@name='Singapore']/year")
> [<Element 'year' at 0x10eb639a8>]
> >>> root.findall(".//neighbor[2]")
> [<Element 'neighbor' at 0x10eb638b8>, <Element 'neighbor' at 0x10eb63c28>]
>
>
> Thanks,
> Senthil
>
> --
> Senthil Kumaran
>
> On Tuesday, June 16, 2015 at 5:55 PM, Noonan wrote:
>
> Sorry my last email sent prematurely, I'm not sure how. I was using a
> hotkey for pasing when it accidently sent.
>
> I'm running Python version:
>
> 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:16:31) [MSC v.1600 64 bit
> (AMD64)]
>
> When I do a .findall or .find on an Element object of an ElementTree from
> xml.etree, xpath queries (of the format './/<tagname>') aren't letting me
> retrieve children that aren't direct descendants of the Element object.
> Also, the documentation doesn't clearly show/when how to use XPath queries,
> it just mentions that you can use them instead. A lot of python
> documentation is like this and it leads to a lot of tinkering and then
> frustration when it doesn't work. Stack overflow said the same solution,
> but really, I think it's sad when your documentation needs stack overflow
> for clarification. Documentation is by no means fast, but the depth should
> be better than a quick search on Google/Bing.
>
> This page is the one I used to read up on it. But I actually found better
> depth/examples in StackOverflow or the site of the guy that I think wrote
> Etree before you guys integrated it into Python.
>
> https://docs.python.org/3/library/xml.etree.elementtree.html?highlight=xml
>
> Thanks!
>
> -Eric
>
> _______________________________________________
> docs mailing list
> docs at python.org
> https://mail.python.org/mailman/listinfo/docs
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20150617/516daa5c/attachment.html>


More information about the docs mailing list