Python 3 support

Thanks to @AcmeProgramming for the idea.