There is often an explanation that "eval (" expression")
is an evaluation of an expression, so the statement cannot be executed. The statement is executed byexec (" statement")
."
Do you notice that these two sentences are inconsistent with each other?
The true nature of the contradiction is that the statement can be executed even though the exec ('sentence')
itself is an expression.
Therefore, ** "the statement cannot be executed because the expression is evaluated" is broken **.
Let's try it with the following example.
Since the exec ('sentence')
itself is an expression, you can put it in eval ("")
.
Really scary home eval
Hoge= "eval shouldn't be able to change the value of a variable"
print(Hoge) #eval shouldn't be able to change the value of a variable
eval("exec('Hoge= \"You can change it\"')")
print(Hoge) #You can change it
There is no such thing as "it's safe because it's eval
".
If you leave it as it is, it will be a big deal.
Recommended Posts