Compatibility with both Python 2(.7) and 3

I've made a few changes to make the Python codes compatible with both Python 2 and 3. I've successfully tested it in Python 2.7 and 3.4.