python - 數(shù)據(jù)無(wú)法插入到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. 淺談vue生命周期共有幾個(gè)階段?分別是什么?2. macos - mac下docker如何設(shè)置代理3. vue添加錨點(diǎn),實(shí)現(xiàn)滾動(dòng)頁(yè)面時(shí)錨點(diǎn)添加相應(yīng)的class操作4. index.php錯(cuò)誤,求指點(diǎn)5. html - 怎么實(shí)現(xiàn)css畫半圓邊框6. javascript - Boolean對(duì)象和基本類型Boolean區(qū)別7. html5 - 一個(gè)用vue組件實(shí)現(xiàn)功能的問題8. css3 - 這個(gè)右下角折角用css怎么畫出來(lái)?9. javascript - 想在編寫weex應(yīng)用的時(shí)候使用rxjs,如何進(jìn)行相關(guān)配置呢?10. javascript - 微信小程序封裝定位問題(封裝異步并可能多次請(qǐng)求)
