mysql取出,转化为[str,str,str....]
2020-01-16 本文已影响0人
月夜星空下
# encoding:utf-8
import mysql.connector # 先安装mysql-connector-python-1.0.12-py3.3,再引入包
import random,readJSON
import re
import codecs
import json
import requests
import time
import os, pprint
import os
from aip import AipNlp
config = {'host': '127.0.0.1',
'user': 'root',
'password': '######',
'port': 3306,
'database': '######',
'charset': 'utf8'
}
try:
cnn = mysql.connector.connect(**config) # connect方法加载config的配置进行数据库的连接,完成后用一个变量进行接收
except mysql.connector.Error as e:
print('数据库链接失败!', str(e))
else: # try没有异常的时候才会执行
print("sucessfully!")
cursor = cnn.cursor(buffered=True) # 获取查询的标记位
dtl_sql = 'select CKey from children_title'
cursor.execute(dtl_sql)
dtl = cursor.fetchall()
new_dtl = list(set(dtl))
add_list_box = []
content_list_box = []
for i in new_dtl:
content = ''
dtl_tupe = i[0]
add_list_box.append(dtl_tupe)
content += i[0]
content_list_box.append(content)
print(content_list_box)