成功解决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格式即可!




 


相关文章
|
3月前
|
存储 语音技术 Python
语音识别,函数综合案例,黑马ATM,/t/t一个对不齐,用两个/t,数据容器入门,数据容器可以分为列表(list)、元组(tuple)、字符串(str)、集合(set)、字典(dict)
语音识别,函数综合案例,黑马ATM,/t/t一个对不齐,用两个/t,数据容器入门,数据容器可以分为列表(list)、元组(tuple)、字符串(str)、集合(set)、字典(dict)
|
4月前
|
前端开发 索引 Python
【已解决】Flask项目报错TypeError: tuple indices must be integers or slices, not str
【已解决】Flask项目报错TypeError: tuple indices must be integers or slices, not str
79 0
TypeError: tuple indices must be integers, not tuple是怎么回事
TypeError: tuple indices must be integers, not tuple是怎么回事
258 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.
1974 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.
890 0
|
5月前
|
Python
Python元组tuple“删除”元素的两种函数代码设计
实际上,Python的tuple元组内的元素是不能被修改的,因此也是无法被删除的,但是,为了移除Python元组tuple内的某些元素,以获得一个新的元组,还是有其办法存在的。比如,我们可以使用for循环添加的方法,来创建一个不包含那些需要被移除的元素的新元组。Python中元组添加元素的内置方法为__add__()方法,实际上,该方法也是
80 4
|
5月前
|
存储 索引 Python
元组(Tuple)在Python编程中的应用与实例
元组(Tuple)在Python编程中的应用与实例
98 2
|
3月前
|
存储 缓存 Python
Python中的列表(List)和元组(Tuple)是两种重要的数据结构
【7月更文挑战第12天】Python中的列表(List)和元组(Tuple)是两种重要的数据结构
47 1
|
4月前
|
存储 Python
Python中list, tuple, dict,set的区别和使用场景
Python中list, tuple, dict,set的区别和使用场景
131 2