Changing from shell script to python