[Python-Dev] bool(container) [was bool(iter()) changedbetween 2.3 and 2.4]
fredrik at pythonware.com
Fri Sep 30 18:29:58 CEST 2005
Guido van Rossum wrote:
> "Containerish" behavior isn't enough to warrant empty <--> false; in
> some sense every object is a container (at least every object with a
> __dict__ attribute) and you sure don't want to map __len__ to
the ElementTree experience shows that doing
def __getitem__(self, index):
is sometimes a good idea, even for objects that are mostly sequences.
(ET 1.2.X lacks the __nonzero__ method, and accidentally treating
elements with no subelements as if the element itself doesn't exist is by
far the most common gotcha in ET code).
More information about the Python-Dev