TypeError: list indices must be integers or slices, not str
错误如下:
TypeError: list indices must be integers or slices, not str
错误代码块:
- aa是一组list套dict数据
- 函数insert接收2个参数,*args,**kwargs
- 我希望把aa这个list传给*args,
- 但在执行程序时却报了一标题显示的错误
首先是关于*args,**kwargs的基本概念:
对于*args和**kwargs在函数中我们可以称之为参数组,但是这两个还是有区别的
1:*args的功能:------接收N个位置参数,转换成元组tuple形式
2:**kwargs的功能------接收N个关键字参数,转换成字典dict形式
3:位置参数一定要在关键字参数之前,也就是(*args,**kwargs)
更多详细内容参照:
https://blog.csdn.net/qq_29053519/article/details/78671323
问题分析:
参数aa前面加*号表示它是一个已经组装好的tuple,否则python会认为aa是一个位置参数
所以这样修改程序即可按照预期运行:
TypeError: list indices must be integers or slices, not str的更多相关文章
- “TypeError: list indices must be integers or slices, not str”有关报错解决方案
- TypeError: string indices must be integers, not str
1. TypeError: string indices must be integers, not str 字符串类型取第index个字符的时候,应该传入int而不是str.如 1 a='abcde ...
- for遍历用例数据时,报错:TypeError: list indices must be integers, not dict,'int' object is not iterable解决方法
一:报错:TypeError: list indices must be integers, not dict for i in range(0,len(test_data)): suite.addT ...
- faster rcnn报错:TypeError: slice indices must be integers or None or have an __index__ method
https://blog.csdn.net/qq_27637315/article/details/78849756 https://blog.csdn.net/qq_21089969/article ...
- python报错 TypeError: string indices must be integers
所以在读取字典的时候,最好先判断类型,然后再查看它是否已经有这样的属性: type(mydict) == type({}) #检查不是字典 如果是字典,再看看有没有这样的属性: ...
- TypeError: slice indices must be integers or None or have an __index__ method
由于除法/自动产生的类型是浮点型,因此出现上述错误,修正方法为,将/更改为// roi_gray_lwpCV = gray_lwpCV[y:y + h // 2, x:x + w] # 检出人脸区域后 ...
- macTypeError: slice indices must be integers or None or have an index method
一般是由于Numpy的版本太高了(1.12对此进行了调整),有的时候传入numpy array里面的索引可能是浮点数,这个时候最好检查一下索引强制转换为int类型 或者安装低版本的numpy sudo ...
- Python处理HTTP返回包遇到问题总结TypeError、keyError、SyntaxError、AttributeError
处理HTTP返回包包括对关键参数的校验,参数完整性检验,获取返回包参数的方法,返回包数据去重方法 在执行时遇到不少问题,部分问题记录如下: 1.报错信息:“TypeError: list indice ...
- Python 基礎 - 列表的使用
如果想要存所有 Marvel's The Avengers 角色的人名,該如何存呢?請用目前已學到的知識來實做- #!/usr/bin/env python3 # -*- coding:utf-8 - ...
随机推荐
- HNUSTOJ 1516:Loky的烦恼
1516: Loky的烦恼 时间限制: 1 Sec 内存限制: 128 MB 提交: 242 解决: 66 [提交][状态][讨论版] 题目描述 loky喜欢上一个女孩,女孩在loky眼中绝对是1 ...
- PHP批量导入excell表格到mysql数据库
PHP批量导入excell表格到mysql数据库,本人通过亲自测试,在这里分享给大家 1,下载 php excell类库 网上搜索可以下载,这里不写地址 2,建html文件 <form met ...
- window-tree命令
tree 以图形方式显示在驱动器中的目录结构或磁盘的路径. 有时候需要整理文档目录时,而文件太多,一个个去写相应的文件目录结构也不现实,就用到了window下的tree命令 语法 tree [< ...
- c# 数据库基础(将连接字符串写到配置文件中)
数据库 操作步骤 一,添加一个配置文件 内容 <?xml version="1.0" encoding="utf-8" ?> <configu ...
- vue手动制作地址选择器
方法一:4级地址选择器(基于elementui Cascader 级联选择器) 推荐 效果图: 组件源码: <template> <div class="select- ...
- linux Apache 的安装
rpm –qa httpd 查询是否安装了 Apache rpm –e 包名卸载安装程序 rpm –e --nodeps 包名卸载安装程序不产生依赖 #检查是否安装有依赖库 yum install – ...
- 01.Linux-CentOS系统清理缓存脚本
#自动清理缓存脚本 [root@k8s-node3 ~]# vim freemem.sh#! /bin/sh#当前已使用内存大小used=`free -m | awk 'NR==2' | awk '{ ...
- 机器学习分类算法之K近邻(K-Nearest Neighbor)
一.概念 KNN主要用来解决分类问题,是监督分类算法,它通过判断最近K个点的类别来决定自身类别,所以K值对结果影响很大,虽然它实现比较简单,但在目标数据集比例分配不平衡时,会造成结果的不准确.而且KN ...
- 合肥学院ACM集训队第一届暑假友谊赛 B FYZ的求婚之旅 D 计算机科学家 F 智慧码 题解
比赛网址:https://ac.nowcoder.com/acm/contest/994#question B FYZ的求婚之旅 思路: 然后用快速幂即可. 细节见代码: #include <i ...
- C\C++下获取系统进程或线程ID(转)
在程序开发时有时需要获取线程和进程ID以分析程序运行 ()windows下获取进程或线程ID 通过调用系统提供的GetCurProcessId或GetNowThreadID来获取当前程序代码运行时的进 ...