To upgrade to python 3, I'm trying to figure out how to write codes in python 2 and python 3. The following code is from python-future.org and illustrates how to create an iterator that is compatible with both versions of python.
from builtins import object class Upper(object): def __init__(self, iterable): self._iter = iter(iterable) def __next__(self):
The code works fine in python 2, but, to my surprise, if I delete the import statement, I get a TypeError: Upper object is not an iterator error TypeError: Upper object is not an iterator . I often derived my custom classes from object , but I never imported it from inline classes. Why does just importing an object change the behavior of the code?
source share