Summary of Python's error-prone points

  1. Python has no code block scope.
    Insert picture description here
    C/C++ language has code block scope.
    Insert picture description here
    Java also has no code block scope.
    Insert picture description here

  2. 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()

Guess you like

Origin blog.csdn.net/herosunly/article/details/105766631