Improved emit_python_code