求助:想输出提取的单词,结果却是字母,这是什么鬼?
#环境变量path "C:\ProgramData\MySQL\MySQL Server 5.7
#-*- coding: utf8 -*-
import pymysql #导入pymysql
#打开数据库链接
conn= pymysql.connect(host="localhost",user="root",passwd="**********",db="database_els",port=3306)
# 使用cusor()方法获取操作游标
cur = conn.cursor()
# 1.查询操作
# 编写sql查询语句,table_dictionaryhighschool, table_materialshighschool对应我的表名
cur.execute( "select group_concat(word) from table_dictionary where wyxxch1qdb1=1 into outfile 'C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/D1.txt' fields terminated by '\.' optionally enclosed by '\"' ;")
#[python] view plaincopy
# -*- coding: utf-8 -*-
import sys
import importlib
importlib.reload(sys)
import string
import re
#encoding:utf8
import os,sys
info=os.getcwd()#获取当前文件名称
fin2 = open('C:\\ProgramData\\MySQL\\MySQL Server 5.7\\Uploads\\D1.txt','rb') #rb表示读写二进制数据
content=fin2.read().decode('utf8') #
words11=[]
count11=0
for line in content:
line =line.replace('"',' ')
line =line.replace('>',' ')
line =line.replace('-',' ')
line =line.replace("."," ")
for word in line.split():
if word.isalpha()==True:
word=word.strip(string.punctuation + string.whitespace +re.sub("[^\u4e00-\u9fa5]","", word))
word=word.lower()
if word not in words11 :
words11.append(word)
count11 =count11 + 1
print (count11, " " ,word)
print (count11,count20)
问题:1. 想提取单词,不想提取的是字母。
2. cur.execute( "select group_concat(word as char) from table_dictionary where wyxxch1qdb1=1 中加上as char, python提示:(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as char) from table_dictionaryhighschool where wyxxch1qdb1=1 group by wyxxch1qdb' at line 1")