Change python code so that it is compatible with Python 2.7 & 3.4
Made additional changes for compatibility with Python 3