Python – 列表索引超出范围 – 在一个简单的SELECT语句上?
发布时间:2020-12-20 13:06:40 所属栏目:Python 来源:网络整理
导读:我是 Python的新手,所以也许我犯了一个新手的错误.但这似乎不是我在这种情况下应该得到的那种错误. 在一个非常简单的SELECT语句中,我得到一个“列表索引超出范围”错误. sql = """ begin tran -- Several update statements are in this block. commit tran"
我是
Python的新手,所以也许我犯了一个新手的错误.但这似乎不是我在这种情况下应该得到的那种错误.
在一个非常简单的SELECT语句中,我得到一个“列表索引超出范围”错误. sql = """ begin tran -- Several update statements are in this block. commit tran""" sql = sql.format(tablename=self.tablename,**self.mappings) #print(sql) self.cursor.execute(sql,(self.catalog_id,self.catalog_id,)) self.cursor.execute("SELECT CaptionText,DisplayOrder FROM dbo.SizeOrder where CaptionText is not NULL and len(CaptionText)>0") #This is the line that breaks! size_order = {row[0].lower(): row[1] for row in self.cursor} 这是最后一排的下一个突破.它没有做任何有趣的格式化.我没有在此问题查询中进行任何替换.直接针对数据库运行时,它返回超过300条记录. 跟踪输出肯定涉及该行代码.我真的怀疑下一行b / c它涉及索引.但执行后的回报没有任何帮助. Traceback (most recent call last): File "import.py",line 782,in <module> main(sys.argv) File "import.py",line 167,in main db.transform_catalog((len(args)>4 and args[4] == "--skipimages") or (len(args)>5 and args[5] == "--skipimages") ) File "import.py",line 235,in transform_catalog self.do_transform(skipImages) File "import.py",line 264,in do_transform self.insert_size_types() File "import.py",line 501,in insert_size_types self.cursor.execute("SELECT CaptionText,DisplayOrder FROM dbo.SizeOrder where CaptionText is not NULL and len(Capt ionText)>0") File "C:Python33libsite-packagespypyodbc.py",line 1449,in execute self._free_stmt(SQL_CLOSE) File "C:Python33libsite-packagespypyodbc.py",line 1971,in _free_stmt check_success(self,ret) File "C:Python33libsite-packagespypyodbc.py",line 986,in check_success ctrl_err(SQL_HANDLE_STMT,ODBC_obj.stmt_h,ret,ODBC_obj.ansi) File "C:Python33libsite-packagespypyodbc.py",line 951,in ctrl_err state = err_list[0][0] IndexError: list index out of range 我能做错什么?谢谢! 解决方法
肯定是一个bug.在库的内部结构中进行某些结果处理时出现无关的错误,而不是与输入相关的错误.
DeepSpace’s link是可能的原因.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |