Converting bash to python