I want to define a class that supports __getitem__, but does not allow iteration.
for example:
class B:
def __getitem__(self, k):
return k
cb = B()
for x in cb:
print x
What could I add to the class B to force the for x in cb: to fail?
I think a slightly better solution would be to raise a TypeError rather than a plain exception (this is what normally happens with a non-iterable class:
Testing: