为了账号安全,请及时绑定邮箱和手机立即绑定

用Python 从Mysql中提取数据并将查询结果写进excel,但返回值不是SQL查询值 而是‘0’求高手指教

用Python 从Mysql中提取数据并将查询结果写进excel,但返回值不是SQL查询值 而是‘0’求高手指教

慕勒13948 2018-12-26 11:26:29
第一步:使用Python 从Mysql中提取数据import pymysql conn = pymysql.connect(host='localhost',user='root',passwd='QAZwsx12345678',db='test',port=3306,charset='utf8') cur = conn.cursor() cur.execute("use test") cur.execute("SELECT Stu_Id FROM student WHERE student.`Name`='王老大'") a = cur.fetchall() b = a.__str__() print(b) cur.close() conn.close返回如图:第二部:使用GUI端,将Mysql的查询结果一键写进excel import tkinter import os import openpyxl from tkinter import * class control :     def __init__(self, master):         fm1 = Frame(master)         Button(fm1, text='Top',command = self.exc).pack(side=TOP, anchor=W, fill=X, expand=NO,padx = 10, pady = 10,ipadx=10,ipady = 4)         fm1.pack(side=LEFT, fill=BOTH, expand=YES)     def exc(self):         wb = openpyxl.load_workbook('C:/Users/lenovo/Desktop/学生.xlsx')         sheet = wb.get_sheet_by_name('学生1')         sheet['A2'] = os.system('C:/Users/lenovo/PycharmProjects/Test.9.16/tests/New_created.py')         print(sheet['A2'].value)         wb.save('学生_copy.xlsx') root = Tk() root.title("Control") display = control(root) root.mainloop()点击GUI按键后得到 返回值 如图:结果:但打开excel 后 发现添加的内容并非SQL的返回值,而是‘0’,请问高手们,这个是为什么?要怎么破呢?
查看完整描述

4 回答

?
pardon110

TA贡献1038条经验 获得超227个赞

注意数据清洗,你的返回值类型是元组,而不是字符串

查看完整回答
1 反对 回复 2018-12-26
  • 4 回答
  • 0 关注
  • 2914 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信