[Python-ideas] __iter__ implies __contains__?

Antoine Pitrou solipsis at pitrou.net
Sat Oct 1 20:13:20 CEST 2011


Hello,

I honestly didn't know we exposed such semantics, and I'm wondering if
the functionality is worth the astonishement:

>>> "abc" in io.StringIO("abc\ndef\n")
False
>>> "abc\n" in io.StringIO("abc\ndef\n")
True

Basically, io.StringIO provides iteration (it yields lines of text) and
containment is apparently inferred from that.

Regards

Antoine.





More information about the Python-ideas mailing list