Answers for "execute string as function python"

8

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
Posted by: Guest on May-31-2020
1

python execute function from string

import foo
method_to_call = getattr(foo, 'bar')
result = method_to_call()
Posted by: Guest on April-07-2020

Code answers related to "execute string as function python"

Python Answers by Framework

Browse Popular Code Answers by Language