Fix python code to work on my python environment. Should be checked for cross-platform compatibility.