Is it possible to run a String text?
Example:
str = "print(2+4)"
Something(str)
Output:
6
Basically turning a string into code, and then running it.
Is it possible to run a String text?
Example:
str = "print(2+4)"
Something(str)
Output:
6
Basically turning a string into code, and then running it.
Use exec as it can dynamically execute code of python programs.
strr = "print(2+4)"
exec(strr)
>> 6
I will not recommend you to use exec
because:
Sure is, looks like your "Something" should be exec.
str = "print(2+4)"
exec(str)
Check out this previous question for more info: How do I execute a string containing Python code in Python?