As explained at
Built-in Functions — Python 3.10.6 documentation[
^], the return value of the
exec
function is always
None
. So your Python script will need to pipe its output into a file which you can then read. Something like:
resp='a = 4; rest = "Expected a = 4. Actual a = {} ".format(a); f = open("foo.txt", "w"); f.write(rest)'
exec(resp)