Andrii V. Mishkovskyi <[EMAIL PROTECTED]> added the comment: 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. ---------- nosy: +mishok13 _______________________________________ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3195> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com