成功解决TypeError: tuple indices must be integers or slices, not str

简介: 成功解决TypeError: tuple indices must be integers or slices, not str

解决问题


TypeError: tuple indices must be integers or slices, not str


for row in cur:  #每行规范输出

    print("name=%s, AGE=%d" % (row['name'], row['age']))



解决思路


类型错误:元组索引必须是整数或切片,而不是字符串。





解决方法


可知cur此时是个tuple或者其他空列表等,而不是dict,只需要将其转为dict格式即可!




 


相关文章
|
存储 语音技术 Python
语音识别,函数综合案例,黑马ATM,/t/t一个对不齐,用两个/t,数据容器入门,数据容器可以分为列表(list)、元组(tuple)、字符串(str)、集合(set)、字典(dict)
语音识别,函数综合案例,黑马ATM,/t/t一个对不齐,用两个/t,数据容器入门,数据容器可以分为列表(list)、元组(tuple)、字符串(str)、集合(set)、字典(dict)
|
前端开发 索引 Python
【已解决】Flask项目报错TypeError: tuple indices must be integers or slices, not str
【已解决】Flask项目报错TypeError: tuple indices must be integers or slices, not str
TypeError: tuple indices must be integers, not tuple是怎么回事
TypeError: tuple indices must be integers, not tuple是怎么回事
521 0
|
Python
TypeError: view must be a callable or a list/tuple in the case of include().
打开微信扫一扫,关注微信公众号【数据与算法联盟】 转载请注明出处:http://blog.csdn.net/gamer_gyt 博主微博:http://weibo.com/234654758 Github:https://github.
2107 0
|
存储 Python
python 序列(list,tuple,str)基本操作
添加元素:  mylist.append()  mylist.extend([1, 2])  mylist.insert(1, "pos") 删除元素:  mylist.remove(value)  #del语句,并非函数  del mylist[pos]  #del mylist #从内存中删除mylist,mylist不存在了  mylist.
998 0
|
Python
Python元组tuple“删除”元素的两种函数代码设计
实际上,Python的tuple元组内的元素是不能被修改的,因此也是无法被删除的,但是,为了移除Python元组tuple内的某些元素,以获得一个新的元组,还是有其办法存在的。比如,我们可以使用for循环添加的方法,来创建一个不包含那些需要被移除的元素的新元组。Python中元组添加元素的内置方法为__add__()方法,实际上,该方法也是
223 4
|
存储 索引 Python
元组(Tuple)在Python编程中的应用与实例
元组(Tuple)在Python编程中的应用与实例
910 2
|
存储 缓存 Python
Python中的列表(List)和元组(Tuple)是两种重要的数据结构
【7月更文挑战第12天】Python中的列表(List)和元组(Tuple)是两种重要的数据结构
418 1
|
存储 安全 编译器
Python学习日记(一:List、Tuple、dictionary)
1.列表、元组和字典都是序列 2.列表字典可以修改和删除序列中的某个元素,而元组就是一个整体,不能修改和删除,一定要修改或删除的话,只能修改和删除整个元组。 3.既然元组不能删除和修改,有什么作用呢? 1.元组比列表遍历速度快,因为元组是一个整体,运算效率高; 2.正是因为不能修改,元组可以保护不需要修改的数据,可以使代码结构更安全。
232 2