This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mishok13
Recipients mishok13, xaka
Date 2008-06-25.09:30:00
SpamBayes Score 0.00031200363
Marked as misclassified No
Message-id <1214386202.79.0.368471797431.issue3195@psf.upfronthosting.co.za>
In-reply-to
Content
To quote Python Library Reference, paragraph 3.1:
"""Any object can be tested for truth value, for use in an if or while
condition or as operand of the Boolean operations below. The following
values are considered false: 
[skipped]
 - instances of user-defined classes, if the class defines a
__nonzero__() or __len__() method, when that method returns the integer
zero or bool value False.
"""
And back to python console:
In [112]: from xml.etree.ElementTree import Element

In [113]: e = Element('foo', {'key': 'value'})

In [114]: len(e)
Out[114]: 0

In [115]: not e
Out[115]: True

This is because Element is just a container and acts more like a list.
So, if you actually append items to this list-like structure, you'll get
this:

In [116]: e.append(Element('bar', {42: 1337}))

In [117]: e.append(Element('baz', {'whatever': 'wherever'}))

In [118]: len(e)
Out[118]: 2

In [119]: not e
Out[119]: False

In conclusion, this just doesn't look like a bug to me. You could try
using "if e is not None" form.
History
Date User Action Args
2008-06-25 09:30:03mishok13setspambayes_score: 0.000312004 -> 0.00031200363
recipients: + mishok13, xaka
2008-06-25 09:30:02mishok13setspambayes_score: 0.000312004 -> 0.000312004
messageid: <1214386202.79.0.368471797431.issue3195@psf.upfronthosting.co.za>
2008-06-25 09:30:01mishok13linkissue3195 messages
2008-06-25 09:30:00mishok13create