python - 使用executemany入库产生pymysql.err.ProgrammingError

查看:490
本文介绍了python - 使用executemany入库产生pymysql.err.ProgrammingError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

错误如下:pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''2016/12/05','0935','9.56','9.56','9.38','9.40','869500','8209314.50\n')' at line 1")

**
插入语句如下:

insert="insert into sz values(%s,%s,%s,%s,%s,%s,%s,%s)"

for f in glob.glob(self.fdir+os.sep+"*.txt"):

        ifile=open(f,'r')
        for line in ifile:
            line=line.split("\t")
            linelist.append(line)
        ifile.close()
    try:
        cursor.executemany(insert,linelist)
    except IndexError:
        pass

**
我是新手,刚开始学python,请问问题出在哪了?

解决方案

应该是换行符号的错误,因为看到你的错误里有'8209313.50\n',从文件取出一行数据你的换行符号每处理,python有标准的读取一行数据的文件操作方法,

这篇关于python - 使用executemany入库产生pymysql.err.ProgrammingError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆