Perl to Python Migration