Changes for Python version 3. And the best is: It works on 2.7, too!