The EXEC statement is used to execute a python statement stored in a string or file. For example, we can generate a string that contains Python code at run time, and then execute the statements using the EXEC statement. The following is a simple example.
>>> exec ' print ' Hello world '
Hello World
Note that the use of the EXEC statement in the example is not the same as Eval_r (), execfile (). EXEC is a statement (like print or while), whereas Eval_r () and execfile () are built-in functions.
An example of understanding the Web:
“
Actually I'm going to use it as the domain name ... Specifically, I want to achieve such an effect ...
There is a class called afunction.
Then run the following code:
Import APPUIFW
D=afunction ("age=10")
Appuifw.note (str (d.age). Decode ("Utf-8"))
Results are output 10.
Solution:
Class Afunction:
def __init__ (self,mystring):
exec ("self.") +mystring)
”
exec executes the stored string (self. AGE=10); So the result is D. Age = 10
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The role of the EXEC () function in Python