python - 數(shù)據(jù)無法插入到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() #創(chuàng)建游標(biāo)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()
上面是代碼,下面是報(bào)錯(cuò)信息
[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獲取到的數(shù)據(jù)也有這些字段,求指導(dǎo)
問題解答
回答1:異常不是提示你了么?code_code 變量沒有定義
相關(guān)文章:
1. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””2. docker - 如何修改運(yùn)行中容器的配置3. docker鏡像push報(bào)錯(cuò)4. 關(guān)于docker下的nginx壓力測(cè)試5. angular.js - angularjs的自定義過濾器如何給文字加顏色?6. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題7. 前端 - @media query 使用出現(xiàn)的問題?8. html5和Flash對(duì)抗是什么情況?9. java - 如何點(diǎn)擊按鈕,重新運(yùn)行(我是初學(xué)者)?10. html - css氣泡,實(shí)現(xiàn)“倒三角(不知道算不算三角了)”可透明的。

網(wǎng)公網(wǎng)安備