Use py2/py3 compatible generator syntax

In py2, generators have gen.next() methods.  In py3, it's gen.__next__().  Using next(gen) works in both versions.