python - 數(shù)據(jù)無(wú)法插入到mysql表里
問(wèn)題描述
# -*- 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)
問(wèn)題解答
回答1:異常不是提示你了么?code_code 變量沒(méi)有定義
相關(guān)文章:
1. linux - 下面這條shell命令怎么用python寫(xiě)啊?2. MySQL 中怎么修改字段名,不更改屬性?3. javascript - 看一些高手寫(xiě)代碼單獨(dú)用 “$”和“_” 來(lái)表示變量,什么時(shí)候單獨(dú)使用這兩個(gè)字符?4. Python爬取網(wǎng)頁(yè)requests亂碼5. ruby - jekyll serve 運(yùn)行報(bào)錯(cuò)6. java - 白盒加密源碼或者庫(kù)7. python - 關(guān)于beautifulsoup獲取文檔內(nèi)容8. android-studio - Android Studio 中有沒(méi)有類(lèi)似C#的#if DEBUG功能9. 如何通過(guò)Java編碼生成Jmeter儀表板報(bào)告。(不是Windows或Shell命令)10. android - WebView偶爾無(wú)法加載,沒(méi)有發(fā)起請(qǐng)求
