run string code example

Example 1: python execute string

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

Example 2: run string

Just use eval command for running string output. As for example:
eval $cmd   #execute command included in string value of $cmd variable
Or for a more sophisticated use run commands stored in lines of a file:
cat commands_file.txt | while read line; do eval $line; done

Tags: