eval( 'import math' )

Ian Kelly ian.g.kelly at gmail.com
Thu Feb 4 09:30:14 EST 2016


On Thu, Feb 4, 2016 at 6:33 AM, 阎兆珣 <yanzhaoxun at greendh.com> wrote:
>    Excuse me for the same problem in Python 3.4.2-32bit
>
>    I just discovered that <eval()> function does not necessarily take the
>    string input and transfer it to a command to execute.
>
>    So is there a problem with my assumption?

eval evaluates an expression, not a statement. For that, you would use exec.

If you're just trying to import though, then you don't need it at all.
Use the importlib.import_module function instead to import a module
determined at runtime. This is more secure than eval or exec, which
can cause any arbitrary Python code to be executed.



More information about the Python-list mailing list