02
MySQL数据查询
import pymysql #创建连接对象 conn = pymysql.connect( host = '127.0.0.1', user = 'root', password = '9890', database = 'paper', charset = 'utf8' ) #执行sql语句 #从conn得到cursor对象 cursor = conn.cursor() sql = "select * from place" cursor.execute(sql) datas = cursor.fetchall() for data in datas: print(data) cursor.close() conn.close()
结巴分词
import pymysql import jieba #创建连接对象 conn = pymysql.connect( host = '127.0.0.1', user = 'root', password = '9890', database = 'paper', charset = 'utf8' ) #执行sql语句 #从conn得到cursor对象 cursor = conn.cursor() sql = "select content from place" cursor.execute(sql) # datas = cursor.fetchall() for data in datas: # print(type(data),data) #tuple转字符串 s =''.join(data); seg_list = jieba.cut(s,cut_all = False) print("Default Mode:"+"/".join(seg_list)) cursor.close() conn.close()
来源:https://www.cnblogs.com/qianchanglai/p/12598693.html