错误如下:

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

错误代码块:

  1. aa是一组list套dict数据
  2. 函数insert接收2个参数,*args,**kwargs
  3. 我希望把aa这个list传给*args,
  4. 但在执行程序时却报了一标题显示的错误

首先是关于*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的更多相关文章

  1. “TypeError: list indices must be integers or slices, not str”有关报错解决方案

  2. TypeError: string indices must be integers, not str

    1. TypeError: string indices must be integers, not str 字符串类型取第index个字符的时候,应该传入int而不是str.如 1 a='abcde ...

  3. 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 ...

  4. 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 ...

  5. python报错 TypeError: string indices must be integers

    所以在读取字典的时候,最好先判断类型,然后再查看它是否已经有这样的属性: type(mydict) == type({})             #检查不是字典 如果是字典,再看看有没有这样的属性: ...

  6. 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] # 检出人脸区域后 ...

  7. macTypeError: slice indices must be integers or None or have an index method

    一般是由于Numpy的版本太高了(1.12对此进行了调整),有的时候传入numpy array里面的索引可能是浮点数,这个时候最好检查一下索引强制转换为int类型 或者安装低版本的numpy sudo ...

  8. Python处理HTTP返回包遇到问题总结TypeError、keyError、SyntaxError、AttributeError

    处理HTTP返回包包括对关键参数的校验,参数完整性检验,获取返回包参数的方法,返回包数据去重方法 在执行时遇到不少问题,部分问题记录如下: 1.报错信息:“TypeError: list indice ...

  9. Python 基礎 - 列表的使用

    如果想要存所有 Marvel's The Avengers 角色的人名,該如何存呢?請用目前已學到的知識來實做- #!/usr/bin/env python3 # -*- coding:utf-8 - ...

随机推荐

  1. PHP批量导入excell表格到mysql数据库

    PHP批量导入excell表格到mysql数据库,本人通过亲自测试,在这里分享给大家 1,下载 php  excell类库 网上搜索可以下载,这里不写地址 2,建html文件 <form met ...

  2. ISC2016训练赛 phrackCTF--Smali

    测试文件:https://static2.ichunqiu.com/icq/resources/fileupload/phrackCTF/REVERSE/Crackme.smali 参考资料:http ...

  3. vuex深入

    多模块  http://www.php.cn/js-tutorial-385084.html Vuex 模块化+命名空间后, 如何调用其他模块的 state, actions, mutations, ...

  4. 2019-8-31-MobaXterm-使用代理

    title author date CreateTime categories MobaXterm 使用代理 lindexi 2019-08-31 16:55:58 +0800 2018-02-13 ...

  5. 基于双XCKU060+双C6678 的双FMC接口40G光纤传输加速计算卡381

    一.板卡概述 板卡采用基于双FPGA+双DSP的信号采集综合处理硬件平台,板卡大小360mmx217mm.板卡两片FPGA提供两个FMC接口,4路QSFP+接口:每片FPGA挂接2簇32-bit DD ...

  6. dos2unix 将DOS格式转换成NUIX格式

    1.命令功能 dos2unix将windows文件格式转换成unix文件格式. 2.语法格式 dos2unix  file 3.使用范例 [root@localhost ~]# dos2unix wi ...

  7. P4513 最大连续字段和 (线段树+区间合并)

    题目链接:https://www.luogu.org/problem/P4513 题目大意:单点修改和求区间最大连续字段和 解题思路:很容易想到是用线段树来做,但是如何进行维护呢? 每个维护区间 [L ...

  8. hdu2955_Robberies 01背包

    有一个强盗要去几个银行偷盗,他既想多投点钱,又想尽量不被抓到.已知各个银行 的金钱数和被抓的概率,以及强盗能容忍的最大被抓概率.求他最多能偷到多少钱? 解:以概率为价值 问价值在合理范围背包的最大容量 ...

  9. man(2) V

    vfork(2) #include <sys/types.h> #include <unistd.h> pid_t vfork(void); 功能:创建子进程并阻塞父进 --- ...

  10. 【GDOI2016模拟3.10】习用之语

    前言 这道题看上去很水,结果我在比赛上浪费了N多时间在上面,但还是没AC.比赛结束后发现:实际上这道题还是是大水. 题目 分析 设字符串c1c2c3c4,其中c1.c2.c3.c4={'0'~'9', ...