python3のクラス定義ではnext()ではなく__next__を使う
クラスの定義の中で、iteratorの部分は
def __iter__(self): プログラム return self def __next__(self): プログラム return 返り値
という書き方をするが、python2ではnext
, python3では__next__
をつかうっぽい。
python3 でnext
を使うと、
TypeError: iter() returned non-iterator of type ...
って怒られる。