Local variables work only in the procedure they are defined in. They don’t work anywhere else.
There is one exception to this – the uselocalvariables statement allows a procedure to temporarily access the local variables of the procedure that called it. The python statement uses this trick to allow you it to access local variables in the code that called it.
When the python( function is used, however, your code is not the calling subroutine. Panorama goes thru quite a few complicated hoops to allow a procedure to be used in a formula, and because of going thru these hoops there is no way for a procedure to access the local variables in code up the chain (if there is any code up the chain, a formula could be used without any calling subroutine).
So, while I suppose this could be considered a bug, this behavior is not likely to ever change. If it did, it would be part of a huge refactor in how custom functions are handled, not as a specific fix to the python( function.
If you want to use local variables, use the python statement instead of the python( function. If you are using the python( function, you’ll need to use either fileglobal, windowglobal or global variables.
Should this included in the documentation for the python( function? Absolutely, and I have just now added this. To be honest, I wasn’t even aware of this issue until the subject came up in this post, so naturally I didn’t document it. This same issue will also affect the shellscript(, applescript(, perl(, ruby( and php( functions, and those help pages have also been updated. This pages won’t be updated in Panorama itself until the next release, but the online versions are already updated.