-
Python has no code block scope.
C/C++ language has code block scope.
Java also has no code block scope.
-
The final result of the format method of a string is a string. But if you use Python to insert data into MySQL, and the input data includes a string, the SQL command should be string of string. The solution is as follows:
if create_date[0] != '\'':
create_date = '\'' + create_date
if create_date[-1] != '\'':
create_date = create_date + '\''
sql = "INSERT INTO mysql_table (id, age, create_date) VALUES ({}, {}, {});"
sql.format(id, age, create_date)
cursor.execute(sql%data)
connect.commit()