История изменений
Исправление MyTrooName, (текущая версия) :
https://docs.python.org/3/library/functions.html#exec
exec(object[, globals[, locals]])
If the globals dictionary does not contain a value for the key __builtins__, a reference to the dictionary of the built-in module builtins is inserted under that key. That way you can control what builtins are available to the executed code by inserting your own __builtins__ dictionary into globals before passing it to exec().
к вопросу об импорте левых модулей:
>>> exec("import os")
>>> exec("import os", {'__builtins__': {}})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
ImportError: __import__ not found
Исходная версия MyTrooName, :
https://docs.python.org/3/library/functions.html#exec
exec(object[, globals[, locals]])
If the globals dictionary does not contain a value for the key __builtins__, a reference to the dictionary of the built-in module builtins is inserted under that key. That way you can control what builtins are available to the executed code by inserting your own __builtins__ dictionary into globals before passing it to exec().