Terry Reedy <[EMAIL PROTECTED]> wrote: >Carl Banks wrote: >> That's not what I was asking for. I was asking for a use case for "if >> x" that can't be replaced by a simple explicit test. Your example >> didn't satisfy that.
> But I believe my example of an iterator with __bool__ but not with > __len__ does. On the other hand, iterators provide a clear example of problems with "if x": __nonzero__ for iterators (in general) returns True even if they are 'empty'. For example, this function (which attempts to avoid making an expensive call when not necessary) is buggy, but easy to write if you've been taught that "if x" will work with any kind of object. def frob(widgets, power): if widgets: frobber = Frobber(power) # expensive call for widget in widgets: frobber.frob(widget) -M- -- http://mail.python.org/mailman/listinfo/python-list