The use and distribution of Pytho is completely free, it is an object-oriented language, it's. Its class module supports high-level concepts such as polymorphism, operator overloading, and multiple inheritance, and is very easy to use with Python's simple syntax and type. Python includes a number of pre-compiled and portable functional modules called the standard library. Python can invoke C and C + + libraries, can be called by C and C + + programs, can be integrated with Java components, communicate with frameworks such as COM and. NET, and can interact with the network through interfaces such as soap, Xml-rpc, and CORBA, so Python is more than just a standalone tool.
Originally intended to use the Eval function to assign a value to the variable, did not expect the invalid syntax error occurred. The source code is as follows
In [2]: eval (' a = 1 ') of File "
", line 1 a = 1 ^syntaxerror:invalid
Syntax
Baidu did not Baidu to the results, and finally found a good answer on the StackOverflow.
The author means that the Eval function is only responsible for processing the expression, and there is no function to assign a value, that is, the Eval function is only responsible for outputting your input, true or false, or something. However, it does not have the ability to affect the current code environment. The EXEC () function should be used if we want to use the assignment. Look at the code:
In [3]: exec (' a = 1 ') in [4]: aout[4]: 1
The solution to the problem has been given, so let's look at the official documentation for the two functions.
eval (expression, Global=none, Local=none)
The parameters are string and optional global and local. Global should be a dictionary file, and local should be a mapping object.
The expression parameter will be processed as a python (strictly speaking, a list of conditional statements), and the global and local parameters will be used as both globally and locally as namespaces.
EXEC (Object[,global,[locals])
This function can provide Python with dynamic code execution capabilities.