I'm trying to make an object which behaves like a string when it is used in "x in y" syntax.
For example, in this case, I want my object "test" behave like the string "ABCDEFG" when I compare it to another string. I think this should be done in the iter function but it doesn't seem to work.
class Test(object):
def __init__(self, var):
self.var = var
def __iter__(self):
return iter(self.var)
>>> test = Test("ABCDEFG")
>>> print "EF" in test # I want this to return True
False
>>> print "EF" in "ABCDEFG" # this is how test should behave
True