ganzewoort
0
Q:

python execute string as code

a = """
A = 5
if A > 0 :
	print("A Is Positive")
elif A == 0 : 
	print("A Is Equal To 0")
else : 
	print("A Is Negative")
"""
exec(a)
>>> A Is Positive
#you can also use eval(string) for asyncio
5
>>>code = """ a = 6+5
           print(a)"""
>>>exec (code)
11

#Just use >>>exec(someString) to execute a string of code.
5

New to Communities?

Join the community