convert from perl to python