Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102496

Re: eval( 'import math' )

From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: eval( 'import math' )
Date 2016-02-04 07:30 -0700
Message-ID <mailman.64.1454596256.30993.python-list@python.org> (permalink)
References <298169014.1288190.1454592838187.JavaMail.root@wmthree-11>

Show all headers | View raw


On Thu, Feb 4, 2016 at 6:33 AM, 阎兆珣 <yanzhaoxun@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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: eval( 'import math' ) Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-04 07:30 -0700

csiph-web