I have bash to run in python code tn.write()
tn.write("a=$(lr 2>logp.txt) \n")
when I run it will error
syntax error: `a=$' unexpected
You cannot run python code directly in your bash. You need to do as follows:
python -c 'tn.write("a=$(lr 2>logp.txt) \n")'
You will encounter other errors, but not in the scope of your question.