成功解决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
完美解决丨2. `TypeError: list indices must be integers or slices, not str`
完美解决丨2. `TypeError: list indices must be integers or slices, not str`
成功解决ValueError: ‘usecols‘ must either be list-like of all strings, all unicode, all integers or a ca
成功解决ValueError: ‘usecols‘ must either be list-like of all strings, all unicode, all integers or a ca
|
Python
解决only integer scalar arrays can be converted to a scalar index
解决only integer scalar arrays can be converted to a scalar index
287 0
解决only integer scalar arrays can be converted to a scalar index
TypeError: tuple indices must be integers, not tuple是怎么回事
TypeError: tuple indices must be integers, not tuple是怎么回事
201 0
|
机器学习/深度学习 索引 Python
【Python·问题解决】IndexError: too many indices for array: array is 2-dimensional, but 3 were indexed
【Python·问题解决】IndexError: too many indices for array: array is 2-dimensional, but 3 were indexed
【Python·问题解决】IndexError: too many indices for array: array is 2-dimensional, but 3 were indexed
TypeError: cannot concatenate ‘str‘ and ‘list‘ objects
TypeError: cannot concatenate ‘str‘ and ‘list‘ objects
|
Linux Python
ValueError: empty range for randrange() (0, 0, 0)
ValueError: empty range for randrange() (0, 0, 0)
|
存储
TypeError: can only concatenate str (not “int“) to str
TypeError: can only concatenate str (not “int“) to str
304 0
TypeError: can only concatenate str (not “int“) to str
成功解决TypeError: slice indices must be integers or None or have an __index__ method
成功解决TypeError: slice indices must be integers or None or have an __index__ method