python - 数据无法插入到mysql表里
天蓬老师
天蓬老师 2017-04-18 10:26:48
0
1
471
# -*- conding:utf8 -*-
import tushare as ts
import pymysql
today_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 변수가 정의되지 않았습니다

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿