Compile text as code, and the execute it:
x = compile('print(55)', 'test', 'eval')
exec(x)
The compile()
function returns the specified source as a code object, ready to be executed.
compile(source, filename, mode, flag, dont_inherit, optimize)
Parameter Values Parameter Description source Required. The source to compile, can be a String, a Bytes object, or an AST object filename Required. The name of the file that the source comes from. If the source does not come from a file, you can write whatever you like mode Required. Legal values:Compile more than one statement, and the execute it:
x = compile('print(55)\nprint(88)', 'test', 'exec')
exec(x)
Track your progress - it's free!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4