This article mainly introduces the new string formatting method in Python3.x. This article compares the example code of the string formatting method in Python2.x and Python3.x, for more information, see Python3.x. Different from Python2.x's
The code is as follows:
"% S" % (a, B)
Python3.x is
The code is as follows:
"{0} {1}". format (a, B)
When I use MySQLdb today
The code is as follows:
Cursor.exe cute (SQL, param)
Statement to complete the SQL operation. It was misled by the old saying in other articles and used
The code is as follows:
Cursor.exe cute ('Insert into test values (% s, % s, % s) ', param)
Param is a tuples that indicate the data to be inserted. each element in the tuples is the value of each column in the database.
However, a database exception is always thrown during execution. error message:
The code is as follows:
[1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(% s, % s, % s) 'At line ...... (Omitted below ).
In fact, you just need to change it to this:
The code is as follows:
Cursor.exe cute ('Insert into test values ({0}, {1}, {2}) ', param)
To be honest, Python3 is incompatible with every pitfall of Python2, increasing the cost of learning Python3. But in order not to impede the development of science and technology and social progress, I decided to join the new version ......