I want to pass few parameters in the python code object. I have tried the below code and it is running fine but I want to know how I can pass the value of a
& b
externally and assign return variable into another variable c
.
codeInString = 'a = 5\nb=6\nsum=a+b\nprint("sum =",sum)\v return sum'
codeObject = compile(codeInString, 'sumstring', 'exec')
exec(codeObject)
Something like this:
codeInString = 'sum=a+b\nprint("sum =",sum) return sum'
codeObject = compile(codeInString, 'sumstring', 'exec')
c = exec(codeObject(a,b))
Please note: I am running this code in a distributed environment.