错误如下:

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. Python 入门之 内置模块 -- time模块

    Python 入门之 内置模块 -- time模块 1.time模块 ​ time翻译过来就是时间,这个模块是与时间相关的模块 import time # 内置模块 -- 标准库 (1)time.ti ...

  2. HNUSTOJ-1253 Babelfish(字典树)

    1253: Problem C: Babelfish 时间限制: 1 Sec  内存限制: 128 MB提交: 14  解决: 3[提交][状态][讨论版] 题目描述 Problem C: Babel ...

  3. C++关于erase的复杂度(转载)

    被这个问题困扰了很多次,有必要整理一下. 当然最好的参考资料就是http://www.cplusplus.com/reference/set/set/erase/ 里的Complexcity部分了,但 ...

  4. vue eslint 规范配置

    vue eslint 规范配置 为了代码格式统一,避免一些低级或者不合理的错误,现强行使用eslint的 standard规范 项目配置 目前都是使用 vue 提供的脚手架进行开发的,虽然 vue-c ...

  5. OD消息断点

    [文章作者]: icefisher[作者邮箱]: 181712814@qq.com[软件下载]: [软件名称]: echap518.exe(只是供学习的crackme)[加壳方式]: 里面直接有个un ...

  6. 时钟管脚设置问题 xilinx ERROR:Place:864 - Incompatible IOB's are locked to the same bank 0

    ERROR:Place:1108 - A clock IOB / BUFGMUX clock component pair have been found   that are not placed ...

  7. diff 比较两个文件的不同

    1.命令功能 diff 逐行比较文件内容,并输出文件差异. 2.语法格式 diff  option   file1    file2 diff  选项   文件1   文件2 参数说明 参数 参数说明 ...

  8. 手写与copy

    m_Font.CreateFont( 14, // 字体高度 0 , // 宽度由系统确定 0 , // 文本不倾斜 0 , // 字体不倾斜 FW_NORMAL, // 字体粗度 0 , // 非斜 ...

  9. mnist 卷积神经网络

    # from keras.models import Sequential# from keras.layers.core import Dense,Activation,Flatten #creat ...

  10. MySQL 赋予用户权限(grant %-远程和localhost-本地区别)

    不过有些时候(有些版本)'%'不包括localhost,要单独对@'localhost'进行赋值,这事真让我遇上了,在对mysql5.1.32建立远程用户时. 分别对'%'和'localhost'授权 ...