Note that I renamed the file variable to f, to avoid shadowing the built-in file.
It has two important mehtodsmethods, first the __iter__ method, which just returns self. This just tells Python that this class is the actual iterator which it can iterate over. It is important for if you nest iter calls, namely iter(iter(tokenizer)) == iter(tokenizer).
Note that since we call iter on the output of the tokenize function, it is enough for tokenize to return an iterable (canthis can be a list, like I defined here here, but it can also be an iterator itself).