import pymysql list=['anhui', 'beijing', 'chongqing', 'fujian', 'gansu', 'guangdong', 'guangxi', 'guizhou', 'hainan', 'hebei', 'heilongjiang', 'henan', 'hubei', 'hunan', 'jiangsu', 'jiangxi', 'jilin', 'liaoning', 'neimenggu', 'ningxia', 'qinghai', 'shaanxi', 'shandong', 'shanghai', 'shanxi', 'sichuan', 'tianjing', 'xinjiang', 'xizang', 'yunnan', 'zhejiang'] for i in list: print(i) conn = pymysql.connect(host='localhost',port=3306,user='root',password='123456',database='zsz') cursor = conn.cursor() sql3= 'update '+i+' set rate=AJS/A where Time between 2010.0 and 2021.0;' try: cursor.execute(sql3) print(‘执行成功’) conn.commit() except Exception as e: conn.rollback() finally: conn.close()