Your explanation is clear. I was assuming that KM interpolates the values of its variables before sending the script to the shell for execution, like this:
n='$KMVAR_fname'; >> n='the actual file name.html';
Please consider that a feature request
The approach I implemented is based on the following post in the forum:
Python Example Code?
This line close to the end of a script passed a KM variable without any interpolation that I could spot:
print ("$KMVAR_filePath");
(I tried both single and double quotes, although Python 3 allows both)
I'm hoping @ComplexPoint will shed some light on how it worked in that script.
I will also look into your suggestion to get Python to read the 'KMVAR_fname' environment variable