Changes for Python3

Inspired in large part by https://wiki.python.org/moin/PortingExtensionModulesToPy3k
Merge pull request #2 from petercombs/master

Changes for Python3