Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8280659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:45:31+00:00 2026-06-08T09:45:31+00:00

I am experiencing some trouble using the Python 2.6.5 xml.etree.ElementTree library. In particular, if

  • 0

I am experiencing some trouble using the Python 2.6.5 xml.etree.ElementTree library. In particular, if I setup a simple xml element like the following

>>> import xml.etree.ElementTree as etree
>>> xml = etree.fromstring("<a><b><c>xy</c></b></a>")

i have no problems with the library when accessing the inner element nodes, e.g.:

>>> etree.tostring(xml.find('b'))
'<b><c>xy</c></b>'
>>> xml.find('b') == None
False
>>> bool(xml.find('b'))
True

However, I am encountering a strange boolean interpretation of leaf element nodes, see:

>>> etree.tostring(xml.find('b/c'))
'<c>xy</c>'
>>> xml.find('b/c') == None
False
>>> bool(xml.find('b/c'))
False

Note that in the last command, the element xml.find(‘b/c’), which is clearly non-None, evaluates to False. This is especially annoying since i cannot use the idiom

>>> leaf = xml.find('b/c'):
>>> if leaf:
>>>     do_stuff(leaf)

to check whether a leaf element exists. (I have to check explicitly for ‘xml.find(‘b/c’) != None’.)

Can someone please explain this (for me unexpected) behavior?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:45:32+00:00Added an answer on June 8, 2026 at 9:45 am

    Ok, sorry, after submitting this question I found the explicit statement of the solution in the Python documentation: http://docs.python.org/release/2.6.5/library/xml.etree.elementtree.html#the-element-interface , at the end of the section.

    Caution: Because Element objects do not define a nonzero() method, elements with no subelements will test as False.

    Sorry for the inconvenience.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am experiencing some performance problems when creating a very simple Python HTTP server.
We are experiencing some random NetConnection.Call.Failed: HTTP: Failed when using the flex 4 mx.messaging.channels::SecureAMFChannel
I'm experiencing some problems with breaking my code to reusable parts using templates and
I'm experiencing some strange behaviour when using a stylus with swing. I am interpreting
I'm experiencing some troubles with Qt's signals and slots mechanism. I have something like
I am new to WPF environment and I am experiencing some problems like if
I have the following class in a Windows Service that is experiencing some vary
I'm experiencing some problems when using the default date:difference EXSLT template, provided at http://www.exslt.org/date/functions/difference/index.html
I'm experiencing some troubles using mnemonic keys in Windows Forms : Simply having a
I'm experiencing some craziness that I just can't figure out. I've created the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.