If I have a string containing some code in a python file. I want to run the code in the string, for example:
program = "for i in range(100):\n\tprint(i)"
eval(program)
However, I'm pretty sure eval only works for mathematical operations, so it throws a syntax error:
Traceback (most recent call last):
File "main.py", line 2, in <module>
eval(program)
File "<string>", line 1
for i in range(100):
^
SyntaxError: invalid syntax
Is there a way in python of running code contained in a string?