cari

Rumah  >  Soal Jawab  >  teks badan

python - 数据无法插入到mysql表里

# -*- 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获取到的数据也有这些字段,求指导

天蓬老师天蓬老师2785 hari yang lalu473

membalas semua(1)saya akan balas

  • 高洛峰

    高洛峰2017-04-18 10:28:48

    Bukankah pengecualian itu memaklumi anda? pembolehubah kod_kod tidak ditakrifkan

    balas
    0
  • Batalbalas