I use Notepad+ for all editing, and so the first thing I checked was that my EOL coding was set to *nix.
I am running "Asterisk 1.4.23-pre.hamvoip-V1.5.3-27-app_rpt-0.327-04/04/2018" which comes with Python 3.5.1
python -V = Python 3.5.1
I can now confirm that changing the one line ...
cmd = "txTg=$1".encode("utf-8")
... works properly without any issues.
Dynamic change of TG's on demand is working great!