Jim Jewett writes: > Python doesn't worry about a precise boolean object, it > distinguishes between something and nothing. > > Is there anything left?" is a pretty good analogy for iterators. [...] > A Queue.Queue is always true. Should I submit a bug patch
I would have phrased this very differently. I would have said it as follows: All Python objects can be converted to a boolean value. Most objects are True, except for False (of course), None, any number equal to 0, an empty string (""), and the empty containers (), [], and {}. User defined objects can override __len__ or __nonzero__ to return False; everything else is True. I don't believe that there is an overarching rule that all "containers" must be false when empty. I'm not sure there is even a clear definition of "container" that would satisfy everyone. It makes complete sense to me that empty iterators and Queue.Queues are True... it follows the general rule that everything is true except the above (short) list of objects and user-defined (or library) classes that want to mimic the behavior of one of these or have some obvious meaning for non-true. -- Michael Chermside _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com