python3 compatibility

This patch should make it both python3 and python2.7 compatible.