How to compile text as code and execute it in Python

1 Answer

0 votes
# compile(source, filename, mode, flag, dont_inherit, optimize)

c = compile('print(100), print(333)', "test", "eval")

exec(c)

 
'''
run:

100
333

'''

 



answered Dec 8, 2018 by avibootz
...