[Python-ideas] __iter__ implies __contains__?

Ron Adam ron3200 at gmail.com
Tue Oct 4 02:18:12 CEST 2011


On Tue, 2011-10-04 at 10:28 +1300, Greg Ewing wrote:
> Ron Adam wrote:
> 
> > Also, we currently don't have an InconclusiveException, which would
> > mean; it may be True or False, but I can't tell, So handle this
> > carefully.
> 
> Um, what does that have to do with iterators?

In Regards to the "in" operator, when "in" can't be used on an iterator
either because it's infinite, or would cause undesirable side effects.

Also cases where an iterator is already partially consumed, that doesn't
mean the value is not in the object being iterated, It's just no longer
in the iterator.

>>> a = 'python'
>>> 'p' in a
True
>>> 'p' in a
True

>>> b = iter(a)
>>> 'p' in b
True
>>> 'p' in b
False

Not really suggesting we have such an exception. For such a thing to
work, it would require adding more state information to iterators.

And of course there's nothing stopping anyone from writing there own
class, and exception, if that type of feature is useful for them.

Cheers,
   Ron





More information about the Python-ideas mailing list