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. 利用百度地图API定位及附件商家信息服务2. 网络爬虫 - python sys 模块 设置编码老是报错3. android - 百度地图拖拽图标后原来位置的图标还在?4. html - 竖线怎么实现5. 求救一下,用新版的phpstudy,数据库过段时间会消失是什么情况?6. javascript - chart.js如何修改某个指定bar的颜色7. pdo_mysql 值自增写法8. python - pip install出现下面图中的报错 什么原因?9. python的文件读写问题?10. mysql新建字段时 timestamp NOT NULL DEFAULT ’0000-00-00 00:00:00’ 报错

网公网安备