Is visible in Python 3? Is visible in Python 3? python python

Is visible in Python 3? has been renamed to g.__next__(). The reason for this is consistency: special methods like __init__() and __del__() all have double underscores (or "dunder" in the current vernacular), and .next() was one of the few exceptions to that rule. This was fixed in Python 3.0. [*]

But instead of calling g.__next__(), use next(g).

[*] There are other special attributes that have gotten this fix; func_name, is now __name__, etc.



Check out this neat table that shows the differences in syntax between 2 and 3 when it comes to this.

If your code must run under Python2 and Python3, use the 2to3 six library like this:

import  # on PY2K: '' and onPY3K: 'next(g)'