Given this perl code: open(FILE,'<',$file) or die("cannot open $file $!"); The generated python code is calling the die() routine if the open succeeds, instead of fails: if(FILE:=open(file,'r')): sys.exit(f"cannot open {file} {sys.last_value}")