Python: moved a variable declaration to the beginning of its function, closes #679