02

青春壹個敷衍的年華 提交于 2020-03-30 15:20:43

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




结巴分词

image-20200330150203660

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!