We know that python3.x introduced a new string formatting syntax. Different from the python2.x.
The code is as follows:
'%s%s '% (A, B)
Python3.x is
The code is as follows:
' {0} {1} '. Format (A, B)
Today, when I was using mysqldb, I needed to use a parameter
The code is as follows:
Cursor.execute (Sql,param)
Statement to complete the SQL operation. Be misled by the old claims of other articles, using
The code is as follows:
Cursor.execute (' INSERT into test values (%s,%s,%s) ', param)
Where Param is a tuple that represents the data to be inserted, each element in the tuple is the value of each column in the database.
But execution always throws a database exception, error message:
The code is as follows:
"1064" You have a error in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-use near ' (%s,%s,%s) ' at line ... (omitted below).
In fact, as long as the change to this is good:
The code is as follows:
Cursor.execute (' INSERT into test values ({0},{1},{2}) ', param)
To tell the truth, Python3 to fill the Python2 of the pits led to the non-compatible, so that the cost of learning Python3 increased a lot. But in order not to hinder the development of science and technology, social progress, I still resolutely devote myself to the new version ...