Fixed a variable scope bug in the python backend