blob: f589cc9a47cea5b4205eb52faab8b4ab17e9bc0f (
plain)
1
2
3
4
5
6
7
8
9
10
11
|
import contextlib
import io
def interpreter(execute):
try:
with io.StringIO() as stdout, contextlib.redirect_stdout(stdout):
exec_data = exec(execute)
return {'message': f'Python successfully interpreted', 'result': stdout.getvalue().strip(), 'text_mode': 'success'}
except Exception as err:
return {'message': f'Python could not be interpreted\nError message: \'{err}\'', 'text_mode': 'danger'}
|