#coding:utf-8 from pymysql import connect data_list=[] # 将数据存入数据库 conn = connect(host="10.36.128.83", port=20002, database="sthjj_sthj", user="lw_lwc", password="***********", charset="utf8") cursor = conn.cursor() try: sql = "SELECT RIVER_SQUARE FROM v_lwhb_river_info" cursor.execute(sql) RIVER_SQUARES=cursor.fetchall() for RIVER_SQUARE in RIVER_SQUARES: RIVER_SQUARE1=list(RIVER_SQUARE) data_list.append(str(RIVER_SQUARE1[0])) print(data_list) print(len(data_list)) except: print('异常!') cursor.close() conn.commit() conn.close() print("*"*100)
脚本执行结构如下,和数据库信息进行比对核实。
标签:读取,python,list,cursor,mysql,print,RIVER,data,conn From: https://www.cnblogs.com/lvjing/p/17858911.html