python - 数据无法插入到mysql表里
问题描述
# -*- conding:utf8 -*-import tushare as tsimport pymysqltoday_data = ts.get_today_all()conn = pymysql.connect(host=’127.0.0.1’, port=3306, user=’root’, passwd=’root’, db=’test’)cursor = conn.cursor() #创建游标cursor.execute('INSERT INTO today_data(code_code,name_name,changepercent,trade,open_open,high_high,low_low,settlement,volume,turnoverratio,amount,per,pb_pb,mktcap,nmc) VALUES (’{}’,’{}’,’{}’,’{}’,’{}’,’{}’,’{}’,’{}’,’{}’,’{}’,’{}’,’{}’,’{}’,’{}’,’{}’)',format(code_code,name_name,changepercent,trade,open_open,high_high,low_low,settlement,volume,turnoverratio,amount,per,pb_pb,mktcap,nmc))cursor.close()
上面是代码,下面是报错信息
[Getting data:]#######################################Traceback (most recent call last): File 'C:/Users/Administrator/PycharmProjects/untitled/test.py', line 7, in <module> cursor.execute('INSERT INTO today_data(code_code,name_name,changepercent,trade,open_open,high_high,low_low,settlement,volume,turnoverratio,amount,per,pb_pb,mktcap,nmc) VALUES (’{}’,’{}’,’{}’,’{}’,’{}’,’{}’,’{}’,’{}’,’{}’,’{}’,’{}’,’{}’,’{}’,’{}’,’{}’)',format(code_code,name_name,changepercent,trade,open_open,high_high,low_low,settlement,volume,turnoverratio,amount,per,pb_pb,mktcap,nmc))NameError: name ’code_code’ is not defined
test中是有today_data表的,表里也有这些字段,变量today_data获取到的数据也有这些字段,求指导
问题解答
回答1:异常不是提示你了么?code_code 变量没有定义
相关文章:
1. linux - 阿里云服务器上的mysql服务在客户端只能通过ssh证书连接后才能使用2. 登录mysql-front出现以下错误3. 微博2输入框一些问题4. (python)关于如何做到按win+R再输入文件文件名就可以运行?5. 急急国王什么梗 我是急急急急急急国王梗内涵出处介绍6. mysql - 博客文章标签表结构设计问题7. python 中文乱码问题8. win10 python3.5 matplotlib使用报错9. python - 图片爬虫时候遇到问题 urllib.request.urlretrieve 下载到指定文件夹不成功?10. python html如何转成PDF?

网公网安备