The former has been thinking of a problem, that is, how to let the user in the graphical interface input code (input code as a string), as part of the code to run, coincides with the Python crawler video tutorial, saw the use of the Eval function,
The eval (), EXEC () two functions in Python and several functions associated with them, such as Globals (), locals (), and compile ():1. Functions of the Eval function:Evaluates the value of the specified expression. That is, the Python code it
English documents:
exec
(object[, globals[, locals]])
This function supports dynamic execution of Python Code.
object must be either a string or a code Object. If It is a string, the string is
Eval functionfunction of FunctionsEvaluates the string str as a valid expression and returns the result of the calculation. The Python code it executes can only be a single operation expression (which does not support arbitrary assignment operations)
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
The eval (str [, Globals [, locals]) function evaluates the string str as a valid Python expression and returns the result of the calculation.Similarly, the EXEC statement executes the string str as valid Python code. The namespace of the code
The eval (STR [, globals [, locals]) function evaluates the string 'str' as a valid Python expression and returns the calculation result.
Similarly, the exec statement executes the string STR as a valid Python code. The namespace provided to the
This log is reproduced, the original link: http://skandgjxa.blog.163.com/blog/static/1415298201010262403483/eval (str [, Globals [, locals]]) function treats the string str as a valid Python tableTo evaluate the value and return the result of the
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
EXEC descriptionEXEC executes python statements stored in a string or file, and can execute more complex Python code than eval,exec.return valueThe exec return value is always None.It should be explained that exec is not a function in Python2, but a
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.