Python 3 compatible

I am trying to use this with Python 3 project, so I made some changed to make it compatible.