Eval (), exec (), execfile (), evalexecexecfile
Eval(Expression[,Globals[,Locals])
The eval () function executes a python expression string and returns the result after the expression is executed:
>>> x = 1>>> eval('x + 1')2
ExpressionThe parameter
0x00 PrefaceEval is a built-in function that Python uses to execute Python expressions, and using eval makes it easy to dynamically execute strings. such as the following code:eval("1+2")eval("[x for x in range(10)]")[0, 1, 2, 3, 4, 5, 6, 7, 8,
Python provides a description of the built-in functions for calling executable objects, involving exec, Eval, and compile three functions. The EXEC statement is used to execute a python statement stored in a code object, a string, a file, and the
1. function declaration Type
Copy Code code as follows:
function foo () {
Code
}
In JS, functions are also objects, function objects are connected to Function.prototype (Function.prototype connected to Object.prototype)
2,
Json.parse with Eval and the ability to parse a string into a JSON object, but it still makes a big difference.Test codevar A = "{ a:1, B: ' Hello '}"; var b = "{ ' a ': 1, ' B ': ' Hello '}"; var C = "{' A ': 1, ' B ': ' Hello '}"; var D = ' {' A
Json.parse with Eval and the ability to parse a string into a JSON object, but it still makes a big difference.Test codevar A = "{ a:1, B: ' Hello '}"; var b = "{ ' a ': 1, ' B ': ' Hello '}"; var C = "{' A ': 1, ' B ': ' Hello '}"; var D = ' {"A":
Ruby has the function facility to execute code saved as strings at runtime, the eval family method. Including kernel # Eval, object # instance_eval, Module # class_eval.
Kernel # eval
It is the most direct method
As follows:
1 p eval("2+2")2 3
When you have to execute a string as code, many people first think of using eval, but in fact, using the new function is more secure. Why is it safe? Look at an example. eval can affect the current scope and all the variables of the parent scope,
Code:
Copy Code code as follows:
Friendly reminder: For your fingers to be safe, please run it under Chrome
' Alert (' Hello ') '. Replace (/.+/, eval);
' Alert (' Hello ') '. Replace (/.+/, function (m) {new function (m) ();});
var i
What are the main aspects of a safe dog:1. Over-injection2. Oversized horses are blocked to visit3. Over chopper connection A word was intercepted4. Over 1.asp;. JPG such a fileI haven't met any of the others.Now at 1.1 o ' Talk:1.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.